use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method reDeployAPI.
public void reDeployAPI(String apiName, String version, String tenantDomain) throws ArtifactSynchronizerException {
SubscriptionDataStore tenantSubscriptionStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
if (tenantSubscriptionStore != null) {
org.wso2.carbon.apimgt.keymgt.model.entity.API retrievedAPI = tenantSubscriptionStore.getApiByNameAndVersion(apiName, version);
if (retrievedAPI != null) {
DeployAPIInGatewayEvent deployAPIInGatewayEvent = new DeployAPIInGatewayEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name(), tenantDomain, retrievedAPI.getApiId(), retrievedAPI.getUuid(), gatewayLabels, apiName, version, retrievedAPI.getApiProvider(), retrievedAPI.getApiType(), retrievedAPI.getContext());
deployAPI(deployAPIInGatewayEvent);
}
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method unDeployAPI.
public void unDeployAPI(DeployAPIInGatewayEvent gatewayEvent) throws ArtifactSynchronizerException {
try {
APIGatewayAdmin apiGatewayAdmin = new APIGatewayAdmin();
MessageContext.setCurrentMessageContext(org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.createAxis2MessageContext());
unDeployAPI(apiGatewayAdmin, gatewayEvent);
} catch (AxisFault axisFault) {
throw new ArtifactSynchronizerException("Error while unDeploying api ", axisFault);
} finally {
MessageContext.destroyCurrentMessageContext();
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method unDeployAPI.
public void unDeployAPI(String apiName, String version, String tenantDomain) throws ArtifactSynchronizerException {
SubscriptionDataStore tenantSubscriptionStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
if (tenantSubscriptionStore != null) {
org.wso2.carbon.apimgt.keymgt.model.entity.API retrievedAPI = tenantSubscriptionStore.getApiByNameAndVersion(apiName, version);
if (retrievedAPI != null) {
DeployAPIInGatewayEvent deployAPIInGatewayEvent = new DeployAPIInGatewayEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name(), tenantDomain, retrievedAPI.getApiId(), retrievedAPI.getUuid(), gatewayLabels, apiName, version, retrievedAPI.getApiProvider(), retrievedAPI.getApiType(), retrievedAPI.getContext());
unDeployAPI(deployAPIInGatewayEvent);
}
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method unDeployAPI.
private void unDeployAPI(APIGatewayAdmin apiGatewayAdmin, DeployAPIInGatewayEvent gatewayEvent) throws AxisFault {
if (gatewayArtifactSynchronizerProperties.isRetrieveFromStorageEnabled()) {
GatewayAPIDTO gatewayAPIDTO = new GatewayAPIDTO();
gatewayAPIDTO.setName(gatewayEvent.getName());
gatewayAPIDTO.setVersion(gatewayEvent.getVersion());
gatewayAPIDTO.setProvider(gatewayEvent.getProvider());
gatewayAPIDTO.setTenantDomain(gatewayEvent.getTenantDomain());
gatewayAPIDTO.setApiId(gatewayEvent.getUuid());
setClientCertificatesToRemoveIntoGatewayDTO(gatewayAPIDTO);
if (APIConstants.API_PRODUCT.equals(gatewayEvent.getApiType())) {
APIProductIdentifier apiProductIdentifier = new APIProductIdentifier(gatewayEvent.getProvider(), gatewayEvent.getName(), gatewayEvent.getVersion());
Set<APIEvent> associatedApis = gatewayEvent.getAssociatedApis();
for (APIEvent associatedApi : associatedApis) {
GatewayUtils.setCustomSequencesToBeRemoved(apiProductIdentifier, associatedApi.getUuid(), gatewayAPIDTO);
GatewayUtils.setEndpointsToBeRemoved(apiProductIdentifier, associatedApi.getUuid(), gatewayAPIDTO);
}
} else {
API api = new API(new APIIdentifier(gatewayEvent.getProvider(), gatewayEvent.getName(), gatewayEvent.getVersion()));
if (APIConstants.APITransportType.GRAPHQL.toString().equalsIgnoreCase(gatewayEvent.getApiType())) {
gatewayAPIDTO.setLocalEntriesToBeRemove(org.wso2.carbon.apimgt.impl.utils.GatewayUtils.addStringToList(gatewayEvent.getUuid().concat("_graphQL"), gatewayAPIDTO.getLocalEntriesToBeRemove()));
DataHolder.getInstance().getApiToGraphQLSchemaDTOMap().remove(gatewayEvent.getUuid());
}
if (APIConstants.APITransportType.WS.toString().equalsIgnoreCase(gatewayEvent.getApiType())) {
org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.setWebsocketEndpointsToBeRemoved(gatewayAPIDTO, gatewayEvent.getTenantDomain());
} else {
GatewayUtils.setEndpointsToBeRemoved(gatewayAPIDTO.getName(), gatewayAPIDTO.getVersion(), gatewayAPIDTO);
}
GatewayUtils.setCustomSequencesToBeRemoved(api, gatewayAPIDTO);
}
gatewayAPIDTO.setLocalEntriesToBeRemove(GatewayUtils.addStringToList(gatewayEvent.getUuid(), gatewayAPIDTO.getLocalEntriesToBeRemove()));
apiGatewayAdmin.unDeployAPI(gatewayAPIDTO);
DataHolder.getInstance().getApiToCertificatesMap().remove(gatewayEvent.getUuid());
DataHolder.getInstance().removeKeyManagerToAPIMapping(gatewayAPIDTO.getApiId());
}
}
use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent 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());
}
}
Aggregations