Skip to content

Commit

Permalink
Merge pull request #490 from aidenkeating/INTLY-2347-amq-update
Browse files Browse the repository at this point in the history
INTLY-2347 Don't use Service Instance for AMQ Online
  • Loading branch information
aidenkeating authored Jul 31, 2019
2 parents f431b36 + f2f7833 commit 81c5741
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 106 deletions.
16 changes: 15 additions & 1 deletion src/common/openshiftResourceDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ const secretDef = namespace => ({
version: 'v1',
namespace
});
const addressSpaceDef = namespace => ({
name: 'addressspaces',
namespace,
version: 'v1beta1',
group: 'enmasse.io'
});
const messagingUserDef = namespace => ({
name: 'messagingusers',
namespace,
version: 'v1beta1',
group: 'user.enmasse.io'
});

export {
namespaceRequestDef,
Expand All @@ -55,5 +67,7 @@ export {
statefulSetDef,
routeDef,
serviceDef,
secretDef
secretDef,
addressSpaceDef,
messagingUserDef
};
17 changes: 14 additions & 3 deletions src/common/serviceInstanceHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import get from 'lodash.get';
import { REJECTED_ACTION } from '../redux/helpers';
import { GET_THREAD } from '../redux/constants/threadConstants';
import { SERVICE_TYPES } from '../redux/constants/middlewareConstants';

class DefaultServiceInstanceTransform {
isTransformable() {
Expand Down Expand Up @@ -113,8 +114,13 @@ const handleServiceInstancesProvision = (namespacePrefix, dispatch, event) => {
* @param si Service Instance Object
* @returns {string} Dashboard URL
*/
const getDashboardUrl = si => {
const { status, metadata } = si;
const getDashboardUrl = svc => {
// Allow for non-Service Instance services
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc.url;
}

const { status, metadata } = svc;
if (status.dashboardURL) {
return status.dashboardURL;
} else if (metadata.annotations && metadata.annotations['integreatly/dashboard-url']) {
Expand All @@ -127,7 +133,12 @@ const findService = (svcName, svcList) => {
if (!svcName || !svcList) {
return null;
}
return svcList.find(svc => get(svc, 'spec.clusterServiceClassExternalName') === svcName);
return svcList.find(svc => {
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc;
}
return get(svc, 'spec.clusterServiceClassExternalName') === svcName;
});
};

const findServices = (svcNames, svcList) => {
Expand Down
39 changes: 25 additions & 14 deletions src/common/walkthroughServiceHelpers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { SERVICE_TYPES, SERVICE_STATUSES } from '../redux/constants/middlewareConstants';

/**
* Retrieves information from a ServiceInstance object that can be used in the
* context of it as a walkthrough service. For example, the GA status of the
* service and a name suitable to be shown in a UI instead of the identifier.
*
* @param {object} svcInstance A ServiceInstance resource.
* @param {object} svc A ServiceInstance resource.
* @returns {object}
*/
const getWalkthroughServiceInfo = svcInstance => {
const { productDetails, spec } = svcInstance;
const getWalkthroughServiceInfo = svc => {
const { productDetails, spec } = svc;

if (productDetails) {
return productDetails;
Expand All @@ -17,16 +19,22 @@ const getWalkthroughServiceInfo = svcInstance => {
};
};

const isServiceProvisioned = svcInstance => {
const readyCondition = getReadyCondition(svcInstance);
const isServiceProvisioned = svc => {
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc.status === SERVICE_STATUSES.PROVISIONED;
}
const readyCondition = getReadyCondition(svc);
if (!readyCondition) {
return false;
}
return readyCondition.status === 'True';
};

const isServiceProvisioning = svcInstance => {
const readyCondition = getReadyCondition(svcInstance);
const isServiceProvisioning = svc => {
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc.status === SERVICE_STATUSES.PROVISIONING;
}
const readyCondition = getReadyCondition(svc);
if (!readyCondition) {
return false;
}
Expand All @@ -36,8 +44,11 @@ const isServiceProvisioning = svcInstance => {
);
};

const isServiceProvisionFailed = svcInstance => {
const readyCondition = getReadyCondition(svcInstance);
const isServiceProvisionFailed = svc => {
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc.status === SERVICE_STATUSES.UNAVAILABLE;
}
const readyCondition = getReadyCondition(svc);
if (!readyCondition) {
return false;
}
Expand All @@ -48,22 +59,22 @@ const isServiceProvisionFailed = svcInstance => {
);
};

const getServiceProvisionMessage = svcInstance => {
const readyCondition = getReadyCondition(svcInstance);
const getServiceProvisionMessage = svc => {
const readyCondition = getReadyCondition(svc);
if (!readyCondition) {
return '';
}
return readyCondition.message;
};

const getReadyCondition = svcInstance => {
const getReadyCondition = svc => {
const {
status: { conditions = [] }
} = svcInstance;
} = svc;
return conditions.find(c => c.type === 'Ready');
};

module.exports = {
export {
getWalkthroughServiceInfo,
isServiceProvisioned,
isServiceProvisioning,
Expand Down
43 changes: 40 additions & 3 deletions src/components/installedAppsView/InstalledAppsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@patternfly/react-core';
import { ChartPieIcon, ErrorCircleOIcon, OnRunningIcon, OffIcon } from '@patternfly/react-icons';
import { getProductDetails } from '../../services/middlewareServices';
import { SERVICE_STATUSES, SERVICE_TYPES } from '../../redux/constants/middlewareConstants';

class InstalledAppsView extends React.Component {
state = {
Expand All @@ -28,10 +29,17 @@ class InstalledAppsView extends React.Component {
}

static isServiceUnready(svc) {
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return !svc.status === SERVICE_STATUSES.PROVISIONED;
}

return !svc.metadata;
}

static isServiceProvisioned(svc) {
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc.status === SERVICE_STATUSES.PROVISIONED;
}
return (
svc.status && svc.status.conditions && svc.status.conditions[0] && svc.status.conditions[0].status === 'True'
);
Expand All @@ -58,6 +66,21 @@ class InstalledAppsView extends React.Component {
<OffIcon /> &nbsp;Not ready
</div>
);
// Allow for non-Service Instance services
if (app.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
if (!app.status || app.status === SERVICE_STATUSES.UNAVAILABLE) {
return unreadyStatus;
}
if (app.status === SERVICE_STATUSES.PROVISIONING) {
return provisioningStatus;
}
if (app.status === SERVICE_STATUSES.PROVISIONED) {
return readyStatus;
}
if (app.status === SERVICE_STATUSES.DELETING) {
return unavailableStatus;
}
}

if (app.metadata && app.metadata.deletionTimestamp) {
return unavailableStatus;
Expand All @@ -73,6 +96,9 @@ class InstalledAppsView extends React.Component {
}

static getRouteForApp(app) {
if (app.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return app.url;
}
if (app.status.dashboardURL) {
return app.status.dashboardURL;
}
Expand Down Expand Up @@ -147,6 +173,10 @@ class InstalledAppsView extends React.Component {
this.props.handleLaunch(svc.spec.clusterServiceClassExternalName);
}

static genUniqueKeyForService(svc) {
return svc.name || svc.spec.clusterServiceClassExternalName;
}

static createMasterList(displayServices, apps, customApps, enableLaunch, launchHandler) {
const completeSvcNames = apps
.map(svc => {
Expand All @@ -159,7 +189,13 @@ class InstalledAppsView extends React.Component {
.concat(displayServices);

const completeSvcList = [...new Set(completeSvcNames)].map(svcName => {
const provisionedSvc = apps.find(svc => svc.spec.clusterServiceClassExternalName === svcName);
const provisionedSvc = apps.find(svc => {
// Allow for non-Service Instance services.
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc.name === svcName;
}
return svc.spec.clusterServiceClassExternalName === svcName;
});
if (!provisionedSvc) {
return {
spec: {
Expand Down Expand Up @@ -189,8 +225,9 @@ class InstalledAppsView extends React.Component {
})
.map((app, index) => {
const { prettyName, gaStatus, hidden } = getProductDetails(app);
const uniqKey = InstalledAppsView.genUniqueKeyForService(app);
return hidden ? null : (
<DataList aria-label="cluster-services-datalist" key={`${app.spec.clusterServiceClassExternalName}`}>
<DataList aria-label="cluster-services-datalist" key={`${uniqKey}`}>
<DataListItem
className={
InstalledAppsView.isServiceProvisioned(app)
Expand All @@ -205,7 +242,7 @@ class InstalledAppsView extends React.Component {
? window.open(InstalledAppsView.getRouteForApp(app).concat('/console'), '_blank')
: window.open(InstalledAppsView.getRouteForApp(app), '_blank');
}}
key={`${app.spec.clusterServiceClassExternalName}_${index}`}
key={`${uniqKey}_${index}`}
value={index}
aria-labelledby={`cluster-service-datalistitem-${index}`}
>
Expand Down
12 changes: 10 additions & 2 deletions src/components/provisioning/provisioningScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
isServiceProvisionFailed
} from '../../common/walkthroughServiceHelpers';
import { getProductDetails } from '../../services/middlewareServices';
import { SERVICE_TYPES } from '../../redux/constants/middlewareConstants';

class ProvisioningScreen extends React.Component {
componentDidMount() {}
Expand Down Expand Up @@ -87,13 +88,20 @@ class ProvisioningScreen extends React.Component {
return null;
}

static buildUniqueServiceKey(svc) {
if (svc.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
return svc.name;
}
return svc.spec.clusterServiceClassExternalName;
}

static renderServiceStatusBar(svc) {
const isProvisionFailed = isServiceProvisionFailed(svc);
return (
<DataListItem
className={`${isProvisionFailed ? 'list-group-error-item' : null}`}
key={svc.spec.clusterServiceClassExternalName}
aria-labelledby={`service-statusbar-datalistitem-${svc.spec.clusterServiceClassExternalName}`}
key={ProvisioningScreen.buildUniqueServiceKey(svc)}
aria-labelledby={`service-statusbar-datalistitem-${ProvisioningScreen.buildUniqueServiceKey(svc)}`}
>
<DataListItemRow>
<DataListItemCells
Expand Down
19 changes: 18 additions & 1 deletion src/components/walkthroughResources/walkthroughResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Badge, Card, TextContent } from '@patternfly/react-core';
import { ChartPieIcon, ExclamationCircleIcon, OnRunningIcon } from '@patternfly/react-icons';
import { getProductDetails } from '../../services/middlewareServices';
import { connect } from '../../redux';
import { SERVICE_TYPES, SERVICE_STATUSES } from '../../redux/constants/middlewareConstants';

class WalkthroughResources extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -58,7 +59,23 @@ class WalkthroughResources extends React.Component {
const readyStatus = <OnRunningIcon className="pf-u-mr-xs integr8ly-state-ready" />;
const unavailableStatus = <ExclamationCircleIcon className="pf-u-mr-xs integr8ly-state-unavailable" />;

if (!app || !app.metadata || (app.metadata && app.metadata.deletionTimestamp)) {
if (!app) {
return unavailableStatus;
}

if (app.type === SERVICE_TYPES.PROVISIONED_SERVICE) {
if (!app.status || app.status === SERVICE_STATUSES.UNAVAILABLE) {
return unavailableStatus;
}
if (app.status === SERVICE_STATUSES.PROVISIONING) {
return provisioningStatus;
}
if (app.status === SERVICE_STATUSES.PROVISIONED) {
return readyStatus;
}
}

if (!app.metadata || (app.metadata && app.metadata.deletionTimestamp)) {
return unavailableStatus;
}

Expand Down
6 changes: 5 additions & 1 deletion src/pages/landing/landingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ const mapDispatchToProps = dispatch => ({
getWalkthroughs: language => dispatch(reduxActions.walkthroughActions.getWalkthroughs(language)),
getCustomWalkthroughs: () => dispatch(reduxActions.walkthroughActions.getCustomWalkthroughs()),
getProgress: () => dispatch(reduxActions.userActions.getProgress()),
launchAMQOnline: (username, namespace) => provisionAMQOnline(dispatch, username, namespace)
launchAMQOnline: (username, namespace) =>
provisionAMQOnline(dispatch, username, namespace).then(a => {
console.log('a', a);
return a;
})
});

const mapStateToProps = state => ({
Expand Down
17 changes: 16 additions & 1 deletion src/redux/constants/middlewareConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ const GET_AMQ_CREDENTIALS = 'GET_AMQ_CREDENTIALS';
const GET_ENMASSE_CREDENTIALS = 'GET_ENMASSE_CREDENTIALS';
const GET_PROVISIONING_USER = 'GET_PROVISIONING_USER';
const GET_CUSTOM_CONFIG = 'GET_CUSTOM_CONFIG';
const PROVISION_SERVICE = 'PROVISION_SERVICE';

const SERVICE_TYPES = {
PROVISIONED_SERVICE: 'PROVISIONED_SERVICE'
};

const SERVICE_STATUSES = {
PROVISIONING: 'PROVISIONING',
PROVISIONED: 'PROVISIONED',
DELETING: 'DELETING',
UNAVAILABLE: 'UNAVAILABLE'
};

export {
CREATE_WALKTHROUGH,
Expand All @@ -13,5 +25,8 @@ export {
GET_AMQ_CREDENTIALS,
GET_ENMASSE_CREDENTIALS,
GET_PROVISIONING_USER,
GET_CUSTOM_CONFIG
GET_CUSTOM_CONFIG,
PROVISION_SERVICE,
SERVICE_STATUSES,
SERVICE_TYPES
};
22 changes: 22 additions & 0 deletions src/redux/reducers/middlewareReducers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { middlewareTypes } from '../constants';
import { FULFILLED_ACTION } from '../helpers';
import { SERVICE_TYPES } from '../constants/middlewareConstants';

const initialState = {
middlewareServices: {
Expand All @@ -19,6 +20,27 @@ const initialState = {
};

const middlewareReducers = (state = initialState, action) => {
// Replacement for CREATE_WALKTHROUGH when services are not ServiceInstances,
// this is more generic.
if (action.type === FULFILLED_ACTION(middlewareTypes.PROVISION_SERVICE)) {
if (!action.payload || !action.payload.name || !action.payload.status) {
return state;
}
const currentSvcs = Object.assign({}, state.middlewareServices.data);
currentSvcs[action.payload.name] = {
type: SERVICE_TYPES.PROVISIONED_SERVICE,
name: action.payload.name,
url: action.payload.url,
status: action.payload.status,
extra: action.payload.extra || {}
};
return Object.assign({}, state, {
middlewareServices: {
...state.middlewareServices,
data: currentSvcs
}
});
}
if (action.type === FULFILLED_ACTION(middlewareTypes.CREATE_WALKTHROUGH)) {
const createData = Object.assign({}, state.middlewareServices.data);
createData[action.payload.spec.clusterServiceClassExternalName] = action.payload;
Expand Down
Loading

0 comments on commit 81c5741

Please sign in to comment.