use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.
the class ExternallyDeployedApiNotifier method process.
/**
* Process API lifecycle notifier events related to APIs deployed in external gateway
*
* @param event related to deployments
* @throws NotifierException if error occurs when casting event
*/
private void process(Event event) throws NotifierException {
APIEvent apiEvent;
apiEvent = (APIEvent) event;
if (APIConstants.EventType.API_LIFECYCLE_CHANGE.name().equals(event.getType())) {
// Handle API retiring life cycle change in external gateway
undeployApiWhenRetiring(apiEvent);
} else if (APIConstants.EventType.API_DELETE.name().equals(event.getType())) {
// Handle API deletion in external gateway
undeployWhenDeleting(apiEvent);
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.
the class ExternallyDeployedApiNotifier method undeployApiWhenRetiring.
/**
* Undeploy APIs from external gateway when life cycle state changed to retire
*
* @param apiEvent APIEvent to undeploy APIs from external gateway
* @throws NotifierException if error occurs when undeploying APIs from external gateway
*/
private void undeployApiWhenRetiring(APIEvent apiEvent) throws NotifierException {
apiMgtDAO = ApiMgtDAO.getInstance();
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
boolean deleted;
String apiId = apiEvent.getUuid();
if (!APIConstants.RETIRED.equals(apiEvent.getApiStatus())) {
return;
}
try {
APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
List<APIRevisionDeployment> test = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiId);
for (APIRevisionDeployment deployment : test) {
String deploymentEnv = deployment.getDeployment();
if (gatewayEnvironments.containsKey(deploymentEnv)) {
ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(gatewayEnvironments.get(deploymentEnv).getProvider());
if (deployer != null) {
try {
deleted = deployer.undeployWhenRetire(api, gatewayEnvironments.get(deploymentEnv));
if (!deleted) {
throw new NotifierException("Error while deleting API product from Solace broker");
}
} catch (DeployerException e) {
throw new NotifierException(e.getMessage());
}
}
}
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method updateAPI.
@Override
public void updateAPI(API api) throws GatewayException {
// build the message to send
APIEvent apiUpdateEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_UPDATE);
apiUpdateEvent.setLabels(api.getLabels());
apiUpdateEvent.setApiSummary(toAPISummary(api));
publishToPublisherTopic(apiUpdateEvent);
if (log.isDebugEnabled()) {
log.debug("API : " + api.getName() + " updated event has been successfully published to broker");
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method deleteAPI.
@Override
public void deleteAPI(API api) throws GatewayException {
// build the message to send
APIEvent apiDeleteEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_DELETE);
apiDeleteEvent.setLabels(api.getLabels());
apiDeleteEvent.setApiSummary(toAPISummary(api));
publishToPublisherTopic(apiDeleteEvent);
if (log.isDebugEnabled()) {
log.debug("API : " + api.getName() + " deleted event has been successfully published to broker");
}
if (api.hasOwnGateway()) {
// Delete the Gateway - check how we can assume that we complete the deletion
try {
List<String> labels = api.getLabels();
if (labels != null && !labels.isEmpty()) {
removeContainerBasedGateway(labels.toArray()[0].toString(), api);
} else {
log.error("Could not delete container based gateways as labels could not find in the API.");
}
} catch (ContainerBasedGatewayException e) {
String msg = "Error while removing the container based gateway";
throw new GatewayException(msg, e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED);
}
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method changeAPIState.
@Override
public void changeAPIState(API api, String status) throws GatewayException {
// create the message to be sent to the gateway. This contains the basic details of the API and target
// lifecycle state.
APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_STATE_CHANGE);
gatewayDTO.setLabels(api.getLabels());
gatewayDTO.setApiSummary(toAPISummary(api));
publishToPublisherTopic(gatewayDTO);
}
Aggregations