use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method deployAPI.
/**
* Deploy an API in the gateway using the deployAPI method in gateway admin.
*
* @param gatewayEvent Gateway Deployment event.
* @return True if API artifact retrieved from the storage and successfully deployed without any error. else false
*/
public boolean deployAPI(DeployAPIInGatewayEvent gatewayEvent) throws ArtifactSynchronizerException {
String apiId = gatewayEvent.getUuid();
Set<String> gatewayLabels = gatewayEvent.getGatewayLabels();
try {
GatewayAPIDTO gatewayAPIDTO = retrieveArtifact(apiId, gatewayLabels);
if (gatewayAPIDTO != null) {
APIGatewayAdmin apiGatewayAdmin = new APIGatewayAdmin();
MessageContext.setCurrentMessageContext(org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.createAxis2MessageContext());
unDeployAPI(apiGatewayAdmin, gatewayEvent);
apiGatewayAdmin.deployAPI(gatewayAPIDTO);
addDeployedCertificatesToAPIAssociation(gatewayAPIDTO);
addDeployedGraphqlQLToAPI(gatewayAPIDTO);
DataHolder.getInstance().addKeyManagerToAPIMapping(apiId, gatewayAPIDTO.getKeyManagers());
if (debugEnabled) {
log.debug("API with " + apiId + " is deployed in gateway with the labels " + String.join(",", gatewayLabels));
}
return true;
}
} catch (IOException | ArtifactSynchronizerException e) {
String msg = "Error deploying " + apiId + " in Gateway";
log.error(msg, e);
throw new ArtifactSynchronizerException(msg, e);
} finally {
MessageContext.destroyCurrentMessageContext();
}
return true;
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException 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.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException 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.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException 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.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method deployAllAPIsAtGatewayStartup.
/**
* Deploy an API in the gateway using the deployAPI method in gateway admin.
*
* @param assignedGatewayLabels - The labels which the gateway subscribed to
* @param tenantDomain tenantDomain of API.
* @return True if all API artifacts retrieved from the storage and successfully deployed without any error. else
* false
*/
public boolean deployAllAPIsAtGatewayStartup(Set<String> assignedGatewayLabels, String tenantDomain) throws ArtifactSynchronizerException {
boolean result = false;
if (gatewayArtifactSynchronizerProperties.isRetrieveFromStorageEnabled()) {
if (artifactRetriever != null) {
try {
int errorCount = 0;
String labelString = String.join("|", assignedGatewayLabels);
String encodedString = Base64.encodeBase64URLSafeString(labelString.getBytes());
APIGatewayAdmin apiGatewayAdmin = new APIGatewayAdmin();
MessageContext.setCurrentMessageContext(org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.createAxis2MessageContext());
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
List<String> gatewayRuntimeArtifacts = ServiceReferenceHolder.getInstance().getArtifactRetriever().retrieveAllArtifacts(encodedString, tenantDomain);
if (gatewayRuntimeArtifacts.size() == 0) {
return true;
}
for (String runtimeArtifact : gatewayRuntimeArtifacts) {
GatewayAPIDTO gatewayAPIDTO = null;
try {
if (StringUtils.isNotEmpty(runtimeArtifact)) {
gatewayAPIDTO = new Gson().fromJson(runtimeArtifact, GatewayAPIDTO.class);
log.info("Deploying synapse artifacts of " + gatewayAPIDTO.getName());
apiGatewayAdmin.deployAPI(gatewayAPIDTO);
addDeployedCertificatesToAPIAssociation(gatewayAPIDTO);
addDeployedGraphqlQLToAPI(gatewayAPIDTO);
DataHolder.getInstance().addKeyManagerToAPIMapping(gatewayAPIDTO.getApiId(), gatewayAPIDTO.getKeyManagers());
}
} catch (AxisFault axisFault) {
log.error("Error in deploying " + gatewayAPIDTO.getName() + " to the Gateway ", axisFault);
errorCount++;
}
}
// reload dynamic profiles to avoid delays in loading certs in mutual ssl enabled APIs upon
// server restart
DynamicProfileReloaderHolder.getInstance().reloadAllHandlers();
if (debugEnabled) {
log.debug("APIs deployed in gateway with the labels of " + labelString);
}
result = true;
// Setting the result to false only if all the API deployments are failed
if (gatewayRuntimeArtifacts.size() == errorCount) {
return false;
}
} catch (ArtifactSynchronizerException | AxisFault e) {
String msg = "Error deploying APIs to the Gateway ";
log.error(msg, e);
return false;
} finally {
MessageContext.destroyCurrentMessageContext();
PrivilegedCarbonContext.endTenantFlow();
}
} else {
String msg = "Artifact retriever not found";
log.error(msg);
throw new ArtifactSynchronizerException(msg);
}
}
return result;
}
Aggregations