use of org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException in project carbon-apimgt by wso2.
the class SolaceApplicationNotifier method removeSolaceApplication.
/**
* Remove applications from Solace broker
*
* @param event ApplicationEvent to remove Solace applications
* @throws NotifierException if error occurs when removing applications from Solace broker
*/
private void removeSolaceApplication(ApplicationEvent event) throws NotifierException {
// get list of subscribed APIs in the application
Subscriber subscriber = new Subscriber(event.getSubscriber());
try {
Set<SubscribedAPI> subscriptions = apiMgtDAO.getSubscribedAPIs(subscriber, event.getApplicationName(), event.getGroupId());
List<SubscribedAPI> subscribedApiList = new ArrayList<>(subscriptions);
boolean hasSubscribedAPIDeployedInSolace = false;
String organizationNameOfSolaceDeployment = null;
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
labelOne: for (SubscribedAPI api : subscribedApiList) {
List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentByApiUUID(api.getUUID());
for (APIRevisionDeployment deployment : deployments) {
if (gatewayEnvironments.containsKey(deployment.getDeployment())) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(gatewayEnvironments.get(deployment.getDeployment()).getProvider())) {
hasSubscribedAPIDeployedInSolace = true;
organizationNameOfSolaceDeployment = gatewayEnvironments.get(deployment.getDeployment()).getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION);
break labelOne;
}
}
}
}
boolean applicationFoundInSolaceBroker = false;
if (hasSubscribedAPIDeployedInSolace) {
SolaceAdminApis solaceAdminApis = SolaceNotifierUtils.getSolaceAdminApis();
// check existence of application in Solace Broker
CloseableHttpResponse response1 = solaceAdminApis.applicationGet(organizationNameOfSolaceDeployment, event.getUuid(), "default");
if (response1.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
applicationFoundInSolaceBroker = true;
if (log.isDebugEnabled()) {
log.info("Found application '" + event.getApplicationName() + "' in Solace broker");
log.info("Waiting until application removing workflow gets finished");
}
} else if (response1.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
throw new NotifierException("Application '" + event.getApplicationName() + "' cannot be found in " + "Solace Broker");
} else {
if (log.isDebugEnabled()) {
log.error("Error while searching for application '" + event.getApplicationName() + "'" + " in Solace Broker. : " + response1.getStatusLine().toString());
}
throw new NotifierException("Error while searching for application '" + event.getApplicationName() + "' in Solace Broker");
}
}
if (applicationFoundInSolaceBroker) {
log.info("Deleting application from Solace Broker");
// delete application from solace
SolaceAdminApis solaceAdminApis = SolaceNotifierUtils.getSolaceAdminApis();
CloseableHttpResponse response2 = solaceAdminApis.deleteApplication(organizationNameOfSolaceDeployment, event.getUuid());
if (response2.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
log.info("Successfully deleted application '" + event.getApplicationName() + "' " + "in Solace Broker");
} else {
if (log.isDebugEnabled()) {
log.error("Error while deleting application " + event.getApplicationName() + " in Solace. :" + response2.getStatusLine().toString());
}
throw new NotifierException("Error while deleting application '" + event.getApplicationName() + "' in Solace");
}
}
} 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 SolaceKeyGenNotifier method process.
/**
* Process Application notifier event related to key generation related to Solace Applications
*
* @param event related to Key generation handling
* @throws NotifierException if error occurs when casting event
*/
private void process(Event event) throws NotifierException {
ApplicationRegistrationEvent applicationRegistrationEvent;
applicationRegistrationEvent = (ApplicationRegistrationEvent) event;
if (APIConstants.EventType.APPLICATION_REGISTRATION_CREATE.name().equals(event.getType())) {
syncSolaceApplicationClientId(applicationRegistrationEvent);
}
}
use of org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException in project carbon-apimgt by wso2.
the class SolaceKeyGenNotifier method syncSolaceApplicationClientId.
/**
* Syncing consumer key of the dev portal applications with applications on the Solace broker
*
* @param event ApplicationEvent to sync Solace applications with dev portal applications
* @throws NotifierException if error occurs when patching applications on the Solace broker
*/
private void syncSolaceApplicationClientId(ApplicationRegistrationEvent event) throws NotifierException {
// get list of subscribed APIs in the application
try {
Application application = apiMgtDAO.getApplicationByUUID(event.getApplicationUUID());
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
Set<SubscribedAPI> subscriptions = apiMgtDAO.getSubscribedAPIs(application.getSubscriber(), application.getName(), application.getGroupId());
boolean isContainsSolaceApis = false;
String organizationNameOfSolaceDeployment = null;
labelOne: // Check whether the application needs to be updated has a Solace API subscription
for (SubscribedAPI api : subscriptions) {
List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentByApiUUID(api.getIdentifier().getUUID());
for (APIRevisionDeployment deployment : deployments) {
if (gatewayEnvironments.containsKey(deployment.getDeployment())) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(gatewayEnvironments.get(deployment.getDeployment()).getProvider())) {
isContainsSolaceApis = true;
organizationNameOfSolaceDeployment = gatewayEnvironments.get(deployment.getDeployment()).getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION);
break labelOne;
}
}
}
}
// Patching consumerKey to Solace application using Admin Apis
if (isContainsSolaceApis) {
if (application.getKeys() != null) {
String consumerSecret = null;
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(CarbonContext.getThreadLocalCarbonContext().getUsername());
Set<APIKey> consumerKeys = apiConsumer.getApplicationKeysOfApplication(application.getId());
for (APIKey key : consumerKeys) {
if (key.getConsumerKey().equals(event.getConsumerKey())) {
consumerSecret = key.getConsumerSecret();
}
}
SolaceNotifierUtils.patchSolaceApplicationClientId(organizationNameOfSolaceDeployment, application, event.getConsumerKey(), consumerSecret);
} else {
throw new NotifierException("Application keys are not found in the application : " + application.getName());
}
}
} 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 ExternalGatewayNotifier method deployApi.
/**
* Deploy APIs to external gateway
*
* @param deployAPIInGatewayEvent DeployAPIInGatewayEvent to deploy APIs to external gateway
* @throws NotifierException if error occurs when deploying APIs to external gateway
*/
private void deployApi(DeployAPIInGatewayEvent deployAPIInGatewayEvent) throws NotifierException {
boolean deployed;
Set<String> gateways = deployAPIInGatewayEvent.getGatewayLabels();
String apiId = deployAPIInGatewayEvent.getUuid();
try {
Map<String, Environment> environments = APIUtil.getEnvironments(deployAPIInGatewayEvent.getTenantDomain());
APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
for (String deploymentEnv : gateways) {
if (environments.containsKey(deploymentEnv)) {
ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(environments.get(deploymentEnv).getProvider());
if (deployer != null) {
try {
deployed = deployer.deploy(api, environments.get(deploymentEnv));
if (!deployed) {
throw new APIManagementException("Error while deploying API product to Solace broker");
}
} catch (DeployerException e) {
throw new APIManagementException(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 ExternalGatewayNotifier method process.
/**
* Process gateway notifier events related to External gateway deployments
*
* @param event related to deployments
* @throws NotifierException if error occurs when casting event
*/
private void process(Event event) throws NotifierException {
DeployAPIInGatewayEvent deployAPIInGatewayEvent;
deployAPIInGatewayEvent = (DeployAPIInGatewayEvent) event;
if (isExternalGatewayAvailableToDeployment(deployAPIInGatewayEvent))
if (APIConstants.EventType.DEPLOY_API_IN_GATEWAY.name().equals(event.getType())) {
deployApi(deployAPIInGatewayEvent);
} else if (APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name().equals(event.getType())) {
unDeployApi(deployAPIInGatewayEvent);
}
}
Aggregations