Skip to content

Commit

Permalink
walkthrough project prep one, one a
Browse files Browse the repository at this point in the history
  • Loading branch information
witmicko committed Oct 2, 2018
1 parent 60ae9f1 commit 74a2119
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 247 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# css
src/**/*.css


# IDE - Intelij
.idea
# IDE - VSCode
.vscode/*
!.vscode/settings.json
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"editor.formatOnSave": true,
"prettier.eslintIntegration": true,
"prettier.singleQuote": true,
"prettier.trailingComma": "none",
Expand Down
84 changes: 15 additions & 69 deletions src/common/openshiftHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,78 +34,24 @@ const findOpenshiftResource = (
* @param {Object} resourceDef The definition of the OpenShift Resource.
* @param {Object} resToFind The OpenShift Resource itself. By default this needs only to contain a name.
* @param {Function} compareFn A custom function for comparing resources, determines if a resource is found.
* @param {Object} resToCreateDef The definition of the OpenShift Resource to create. e.g find kind: Project, but create kind: ProjectRequest
* @param {Object} resToCreateObj The OpenShift Resource to create
*/
const findOrCreateOpenshiftResource = (resourceDef, resource, compareFn) =>
findOpenshiftResource(resourceDef, resource, compareFn).then(foundResource => {
const findOrCreateOpenshiftResource = (
resourceDef,
resourceToFind,
compareFn,
resourceToCreateDef,
resourceToCreateObj
) =>
findOpenshiftResource(resourceDef, resourceToFind, compareFn).then(foundResource => {
if (!foundResource) {
return create(resourceDef, resource);
if (resourceToCreateDef && resourceToCreateObj) {
return create(resourceToCreateDef, resourceToCreateObj);
}
create(resourceDef, resourceToFind);
}
return Promise.resolve(foundResource);
});

const namespaceRequestDef = {
name: 'projectrequests',
version: 'v1',
group: 'project.openshift.io'
};
const namespaceRequestResource = name => ({
kind: 'ProjectRequest',
metadata: {
name
}
});
const namespaceDef = {
name: 'projects',
version: 'v1',
group: 'project.openshift.io'
};
const namespaceResource = name => ({
kind: 'projects',
metadata: {
name
}
});
const statefulSetDef = namespace => ({
name: 'statefulsets',
group: 'apps',
version: 'v1beta1',
namespace
});
const routeDef = namespace => ({
name: 'routes',
group: 'route.openshift.io',
version: 'v1',
namespace
});
const serviceInstanceDef = namespace => ({
name: 'serviceinstances',
namespace,
version: 'v1beta1',
group: 'servicecatalog.k8s.io'
});
const serviceDef = namespace => ({
name: 'services',
namespace,
version: 'v1'
});
const secretDef = namespace => ({
name: 'secrets',
version: 'v1',
namespace
});

export {
buildValidProjectNamespaceName,
cleanUsername,
findOrCreateOpenshiftResource,
findOpenshiftResource,
namespaceRequestDef,
namespaceRequestResource,
namespaceDef,
serviceInstanceDef,
namespaceResource,
statefulSetDef,
routeDef,
serviceDef,
secretDef
};
export { buildValidProjectNamespaceName, findOrCreateOpenshiftResource, findOpenshiftResource };
62 changes: 62 additions & 0 deletions src/common/openshiftResourceDefinitions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const namespaceRequestDef = {
name: 'projectrequests',
version: 'v1',
group: 'project.openshift.io'
};
const namespaceRequestResource = name => ({
kind: 'ProjectRequest',
metadata: {
name
}
});
const namespaceDef = {
name: 'projects',
version: 'v1',
group: 'project.openshift.io'
};
const namespaceResource = name => ({
kind: 'projects',
metadata: {
name
}
});
const statefulSetDef = namespace => ({
name: 'statefulsets',
group: 'apps',
version: 'v1beta1',
namespace
});
const routeDef = namespace => ({
name: 'routes',
group: 'route.openshift.io',
version: 'v1',
namespace
});
const serviceInstanceDef = namespace => ({
name: 'serviceinstances',
namespace,
version: 'v1beta1',
group: 'servicecatalog.k8s.io'
});
const serviceDef = namespace => ({
name: 'services',
namespace,
version: 'v1'
});
const secretDef = namespace => ({
name: 'secrets',
version: 'v1',
namespace
});

export {
namespaceRequestDef,
namespaceRequestResource,
namespaceDef,
serviceInstanceDef,
namespaceResource,
statefulSetDef,
routeDef,
serviceDef,
secretDef
};
61 changes: 47 additions & 14 deletions src/common/serviceInstanceHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* eslint class-methods-use-this: ["error", { "exceptMethods": ["isTransformable", "transform"] }] */
import { OpenShiftWatchEvents } from '../services/openshiftServices';
import { GET_WALKTHROUGH_SERVICE } from '../redux/constants/walkthroughServicesConstants';
import { FULFILLED_ACTION } from '../redux/helpers';

class DefaultServiceInstanceTransform {
isTransformable() {
return true;
Expand Down Expand Up @@ -31,29 +35,29 @@ class AMQServiceInstanceTransform {
}
}

class CRUDAppInstanceTransform {
class EnMasseServiceInstanceTransform {
isTransformable(siInfo) {
return siInfo.name === DEFAULT_SERVICES.CRUD_APP;
return siInfo.name === DEFAULT_SERVICES.ENMASSE;
}

transform(siInfo) {
const defaultTransform = new DefaultServiceInstanceTransform().transform(siInfo);
defaultTransform.spec.clusterServicePlanExternalName = 'default';
defaultTransform.spec.parameters = {
name: siInfo.username
};
defaultTransform.spec.clusterServicePlanExternalName = 'unlimited-standard';
return defaultTransform;
}
}

class EnMasseServiceInstanceTransform {
class CRUDAppInstanceTransform {
isTransformable(siInfo) {
return siInfo.name === DEFAULT_SERVICES.ENMASSE;
return siInfo.name === DEFAULT_SERVICES.CRUD_APP;
}

transform(siInfo) {
const defaultTransform = new DefaultServiceInstanceTransform().transform(siInfo);
defaultTransform.spec.parameters = {
name: siInfo.username
};
defaultTransform.spec.clusterServicePlanExternalName = 'unlimited-standard';
defaultTransform.spec.clusterServicePlanExternalName = 'default';
return defaultTransform;
}
}
Expand All @@ -66,11 +70,13 @@ class MessagingAppServiceInstanceTransform {
transform(siInfo) {
const defaultTransform = new DefaultServiceInstanceTransform().transform(siInfo);
defaultTransform.spec.clusterServicePlanExternalName = 'default';

defaultTransform.spec.parameters = {
MESSAGING_SERVICE_PASSWORD: siInfo.amqCredentials.password,
MESSAGING_SERVICE_USER: siInfo.amqCredentials.username,
MESSAGING_SERVICE_HOST: siInfo.amqCredentials.url
MESSAGING_SERVICE_PASSWORD: siInfo.otherData.password,
MESSAGING_SERVICE_USER: siInfo.otherData.username,
MESSAGING_SERVICE_HOST: siInfo.otherData.url
};

return defaultTransform;
}
}
Expand All @@ -84,6 +90,7 @@ const DEFAULT_SERVICES = {
CRUD_APP: 'spring-boot-rest-http-crud',
MESSAGING_APP: 'nodejs-messaging-work-queue-frontend'
};

const DEFAULT_TRANSFORMS = [
new EnMasseServiceInstanceTransform(),
new AMQServiceInstanceTransform(),
Expand Down Expand Up @@ -113,10 +120,36 @@ const buildServiceInstanceResourceObj = (siInfo, transforms = DEFAULT_TRANSFORMS
const buildServiceInstanceCompareFn = si => res =>
res.spec.clusterServiceClassExternalName === si.spec.clusterServiceClassExternalName;

const handleWalkthroughOneRoutes = (dispatch, event) => {
if (
event.type === OpenShiftWatchEvents.OPENED ||
event.type === OpenShiftWatchEvents.CLOSED ||
event.type === OpenShiftWatchEvents.DELETED
) {
return;
}

const route = event.payload;
if (
route &&
route.spec &&
route.spec.to &&
(route.spec.to.name === DEFAULT_SERVICES.CRUD_APP || route.spec.to.name === DEFAULT_SERVICES.MESSAGING_APP)
) {
dispatch({
type: FULFILLED_ACTION(GET_WALKTHROUGH_SERVICE),
payload: route
});
}
};

export {
buildServiceInstanceCompareFn,
buildServiceInstanceResourceObj,
CRUDAppInstanceTransform,
DEFAULT_SERVICES,
DefaultServiceInstanceTransform,
EnMasseServiceInstanceTransform,
buildServiceInstanceCompareFn,
DEFAULT_SERVICES
handleWalkthroughOneRoutes,
MessagingAppServiceInstanceTransform
};
22 changes: 15 additions & 7 deletions src/pages/tutorial/task/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { noop, Alert, Button, ButtonGroup, Checkbox, Grid, Icon, ProgressBar } f
import { connect, reduxActions } from '../../../redux';
import Breadcrumb from '../../../components/breadcrumb/breadcrumb';
import AsciiDocTemplate from '../../../components/asciiDocTemplate/asciiDocTemplate';
import { provisionWalkthroughOne } from '../../../services/walkthroughProvisionServices';
import { prepareWalkthroughNamespace, walkthroughs } from '../../../services/walkthroughServices';

class TaskPage extends React.Component {
state = { task: 0, verifications: {}, verificationsChecked: false };

componentDidMount() {
this.loadThread();
const { provisionWalkthroughOne } = this.props;
const { prepareWalkthroughOne, prepareWalkthroughOneA } = this.props;
if (this.props.match.params.id === '1') {
provisionWalkthroughOne(this.props.middlewareServices.amqCredentials);
prepareWalkthroughOne(this.props.middlewareServices.amqCredentials);
}
if (this.props.match.params.id === '1A') {
prepareWalkthroughOneA(this.props.middlewareServices.enmasseCredentials);
}
}

Expand Down Expand Up @@ -287,7 +290,8 @@ TaskPage.propTypes = {
}),
getThread: PropTypes.func,
middlewareServices: PropTypes.object,
provisionWalkthrough: PropTypes.func,
prepareWalkthroughOne: PropTypes.func,
prepareWalkthroughOneA: PropTypes.func,
setProgress: PropTypes.func,
thread: PropTypes.object,
user: PropTypes.object
Expand All @@ -306,17 +310,21 @@ TaskPage.defaultProps = {
getThread: noop,
middlewareServices: {
data: {},
amqCredentials: {}
amqCredentials: {},
enmasseCredentials: {}
},
provisionWalkthrough: noop,
prepareWalkthroughOne: noop,
prepareWalkthroughOneA: noop,
setProgress: noop,
thread: null,
user: null
};

const mapDispatchToProps = dispatch => ({
getThread: (language, id) => dispatch(reduxActions.threadActions.getThread(language, id)),
provisionWalkthrough: amqCredentials => provisionWalkthroughOne(dispatch, amqCredentials),
prepareWalkthroughOne: amqCredentials => prepareWalkthroughNamespace(dispatch, walkthroughs.one, amqCredentials),
prepareWalkthroughOneA: enmasseCredentials =>
prepareWalkthroughNamespace(dispatch, walkthroughs.oneA, enmasseCredentials),
setProgress: progress => dispatch(reduxActions.userActions.setProgress(progress))
});

Expand Down
3 changes: 1 addition & 2 deletions src/redux/reducers/walkthroughServiceReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const initialState = {
const walkthroughServiceReducers = (state = initialState, action) => {
if (action.type === FULFILLED_ACTION(GET_WALKTHROUGH_SERVICE)) {
const createData = Object.assign({}, state.walkthroughServices.services);
createData[action.payload.spec.to.name] = action.payload;
console.log('Create Data', createData);
createData[`${action.payload.metadata.namespace}-${action.payload.spec.to.name}`] = action.payload;
return Object.assign({}, state, {
walkthroughServices: {
...state.walkthroughServices,
Expand Down
Loading

0 comments on commit 74a2119

Please sign in to comment.