use of org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException in project carbon-apimgt by wso2.
the class ExternallyDeployedApiNotifier method undeployWhenDeleting.
/**
* Undeploy APIs from external gateway when API is deleted
*
* @param apiEvent APIEvent to undeploy APIs from external gateway
* @throws NotifierException if error occurs when undeploying APIs from external gateway
*/
private void undeployWhenDeleting(APIEvent apiEvent) throws NotifierException {
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
boolean deleted;
String apiId = apiEvent.getUuid();
try {
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.undeploy(apiEvent.getApiName(), apiEvent.getApiVersion(), apiEvent.getApiContext(), 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.exceptions.NotifierException in project carbon-apimgt by wso2.
the class SolaceApplicationNotifier method process.
/**
* Process Application notifier event related to Solace applications
*
* @param event related to Application handling
* @throws NotifierException if error occurs when casting event
*/
private void process(Event event) throws NotifierException {
ApplicationEvent applicationEvent;
applicationEvent = (ApplicationEvent) event;
if (APIConstants.EventType.APPLICATION_DELETE.name().equals(event.getType())) {
removeSolaceApplication(applicationEvent);
} else if (APIConstants.EventType.APPLICATION_UPDATE.name().equals(event.getType())) {
renameSolaceApplication(applicationEvent);
}
}
use of org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException in project carbon-apimgt by wso2.
the class SolaceSubscriptionsNotifier method updateSubscription.
/**
* Update subscriptions related to Solace APIs
*
* @param event SubscriptionEvent to update Solace API subscriptions
* @throws NotifierException if error occurs when updating subscription for Solace APIs
*/
private void updateSubscription(SubscriptionEvent event) throws NotifierException {
String apiUUID = event.getApiUUID();
String applicationUUID = event.getApplicationUUID();
try {
APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
API api = apiProvider.getAPIbyUUID(apiUUID, apiMgtDAO.getOrganizationByAPIUUID(apiUUID));
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(CarbonContext.getThreadLocalCarbonContext().getUsername());
Application application = apiMgtDAO.getApplicationByUUID(applicationUUID);
Set<APIKey> consumerKeys = apiConsumer.getApplicationKeysOfApplication(application.getId());
for (APIKey apiKey : consumerKeys) {
application.addKey(apiKey);
}
// Check whether the subscription is belongs to an API deployed in Solace
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(api.getGatewayVendor())) {
ArrayList<String> solaceApiProducts = new ArrayList<>();
List<Environment> deployedSolaceEnvironments = SolaceNotifierUtils.getDeployedSolaceEnvironmentsFromRevisionDeployments(api);
String applicationOrganizationName = SolaceNotifierUtils.getSolaceOrganizationName(deployedSolaceEnvironments);
if (applicationOrganizationName != null) {
try {
boolean apiProductDeployedIntoSolace = SolaceNotifierUtils.checkApiProductAlreadyDeployedIntoSolaceEnvironments(api, deployedSolaceEnvironments);
if (apiProductDeployedIntoSolace) {
for (Environment environment : deployedSolaceEnvironments) {
solaceApiProducts.add(SolaceNotifierUtils.generateApiProductNameForSolaceBroker(api, environment.getName()));
}
SolaceNotifierUtils.deployApplicationToSolaceBroker(application, solaceApiProducts, applicationOrganizationName);
}
} catch (IOException e) {
log.error(e.getMessage());
}
} else {
if (log.isDebugEnabled()) {
log.error("Cannot create solace application " + application.getName() + "with API product " + "deployed in different organizations...");
}
throw new APIManagementException("Cannot create solace application " + application.getName() + "with API product deployed in different organizations...");
}
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException in project carbon-apimgt by wso2.
the class SolaceSubscriptionsNotifier method removeSubscription.
/**
* Remove subscriptions from Solace APIs
*
* @param event SubscriptionEvent to remove Solace API subscriptions
* @throws NotifierException if error occurs when deleting subscriptions from Solace APIs
*/
private void removeSubscription(SubscriptionEvent event) throws NotifierException {
String apiUUID = event.getApiUUID();
String applicationUUID = event.getApplicationUUID();
try {
APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
API api = apiProvider.getAPIbyUUID(apiUUID, apiMgtDAO.getOrganizationByAPIUUID(apiUUID));
Application application = apiProvider.getApplicationByUUID(applicationUUID);
// Check whether the subscription is belongs to an API deployed in Solace
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(api.getGatewayVendor())) {
SolaceNotifierUtils.unsubscribeAPIProductFromSolaceApplication(api, application);
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException in project carbon-apimgt by wso2.
the class SolaceSubscriptionsNotifier method process.
/**
* Process gateway notifier events related to Solace API subscriptions
*
* @param event related to subscription handling
* @throws NotifierException if error occurs when casting event
*/
private void process(Event event) throws NotifierException {
SubscriptionEvent subscriptionEvent;
subscriptionEvent = (SubscriptionEvent) event;
if (APIConstants.EventType.SUBSCRIPTIONS_CREATE.name().equals(event.getType())) {
crateSubscription(subscriptionEvent);
} else if (APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name().equals(event.getType())) {
updateSubscription(subscriptionEvent);
} else if (APIConstants.EventType.SUBSCRIPTIONS_DELETE.name().equals(event.getType())) {
removeSubscription(subscriptionEvent);
}
}
Aggregations