use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method getContainerBasedGatewayGenerator.
/**
* Get Container Based Gateway Generator
*
* @return containerBasedGatewayGenerator
* @throws ContainerBasedGatewayException if error occurred while initializing container based gateway generator
*/
public ContainerBasedGatewayGenerator getContainerBasedGatewayGenerator() throws ContainerBasedGatewayException {
if (containerBasedGatewayGenerator == null) {
try {
ContainerBasedGatewayConfiguration containerBasedGatewayConfiguration = ContainerBasedGatewayConfigBuilder.getContainerBasedGatewayConfiguration();
String implClassName = containerBasedGatewayConfiguration.getImplClass();
Map<String, String> implParameters = containerBasedGatewayConfiguration.getImplParameters();
containerBasedGatewayGenerator = (ContainerBasedGatewayGenerator) Class.forName(implClassName).newInstance();
containerBasedGatewayGenerator.initImpl(implParameters);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new ContainerBasedGatewayException("Error occurred while initializing container based gateway " + "generator", e, ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
}
return containerBasedGatewayGenerator;
}
use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.
the class APIStateChangeWorkflow method completeWorkflow.
@Override
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
WorkflowResponse response = workflowExecutor.complete(this);
setStatus(response.getWorkflowStatus());
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("API state change workflow complete: Approved");
}
String invoker = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_LC_INVOKER);
String currentState = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_CUR_STATE);
String targetState = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_TARGET_STATE);
boolean hasOwnGateway = Boolean.valueOf(getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_HAS_OWN_GATEWAY));
String label = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_AUTOGEN_LABEL);
if (hasOwnGateway) {
// (CREATED to DEPRECATED)
if ((currentState.equalsIgnoreCase(APIStatus.CREATED.getStatus()) || currentState.equalsIgnoreCase(APIStatus.MAINTENANCE.getStatus()) || currentState.equalsIgnoreCase(APIStatus.PROTOTYPED.getStatus())) && (targetState.equalsIgnoreCase(APIStatus.PUBLISHED.getStatus()) || targetState.equalsIgnoreCase(APIStatus.PROTOTYPED.getStatus()) || targetState.equalsIgnoreCase(APIStatus.DEPRECATED.getStatus()))) {
try {
// No need to auto-generate the label again As hasOwnGateway is true.
// create the gateway
API api = apiDAO.getAPI(getWorkflowReference());
apiGateway.createContainerBasedGateway(label, api);
} catch (ContainerBasedGatewayException e) {
// Revert already added labels
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(false);
dedicatedGateway.setApiId(getWorkflowReference());
dedicatedGateway.setUpdatedBy(invoker);
List<String> labels = new ArrayList<>();
labels.add(labelDAO.getLabelIdByNameAndType(APIMgtConstants.DEFAULT_LABEL_NAME, APIMgtConstants.LABEL_TYPE_GATEWAY));
labels.add(labelDAO.getLabelIdByNameAndType(APIMgtConstants.DEFAULT_LABEL_NAME, APIMgtConstants.LABEL_TYPE_STORE));
apiDAO.updateDedicatedGateway(dedicatedGateway, labels);
throw new APIManagementException("Error while updating lifecycle state in Private Jet Mode", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
}
}
}
String localTime = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_LAST_UPTIME);
LocalDateTime time = LocalDateTime.parse(localTime);
updateAPIStatusForWorkflowComplete(getWorkflowReference(), targetState, invoker, time);
// After publishing the state change to the Gateway, remove the gateway for following occasions.
if (hasOwnGateway) {
if ((currentState.equalsIgnoreCase(APIStatus.PUBLISHED.getStatus()) || currentState.equalsIgnoreCase(APIStatus.PROTOTYPED.getStatus()) || currentState.equalsIgnoreCase(APIStatus.DEPRECATED.getStatus())) && (targetState.equalsIgnoreCase(APIStatus.CREATED.getStatus()) || targetState.equalsIgnoreCase(APIStatus.MAINTENANCE.getStatus()) || targetState.equalsIgnoreCase(APIStatus.PROTOTYPED.getStatus())) || targetState.equalsIgnoreCase(APIStatus.RETIRED.getStatus())) {
// remove gateway
API api = apiDAO.getAPI(getWorkflowReference());
apiGateway.removeContainerBasedGateway(label, api);
}
}
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("API state change workflow complete: Rejected");
}
apiDAO.updateAPIWorkflowStatus(getWorkflowReference(), APIMgtConstants.APILCWorkflowStatus.REJECTED);
}
updateWorkflowEntries(this);
return response;
}
Aggregations