use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class APIConsumerImpl method getOpenAPIDefinitionForDeployment.
/**
* Get server URL updated Open API definition for given synapse gateway environment
* @param environmentName Name of the synapse gateway environment
* @return Updated Open API definition
* @throws APIManagementException
*/
private String getOpenAPIDefinitionForDeployment(API api, String environmentName) throws APIManagementException {
String apiTenantDomain;
String updatedDefinition = null;
Map<String, String> hostsWithSchemes;
String definition;
if (api.getSwaggerDefinition() != null) {
definition = api.getSwaggerDefinition();
} else {
throw new APIManagementException("Missing API definition in the api " + api.getUuid());
}
APIDefinition oasParser = OASParserUtil.getOASParser(definition);
api.setScopes(oasParser.getScopes(definition));
api.setUriTemplates(oasParser.getURITemplates(definition));
apiTenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(api.getId().getProviderName()));
hostsWithSchemes = getHostWithSchemeMappingForEnvironment(api, apiTenantDomain, environmentName);
api.setContext(getBasePath(apiTenantDomain, api.getContext()));
updatedDefinition = oasParser.getOASDefinitionForStore(api, definition, hostsWithSchemes);
return updatedDefinition;
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class APIAdminImpl method updateEnvironment.
@Override
public Environment updateEnvironment(String tenantDomain, Environment environment) throws APIManagementException {
// check if the VHost exists in the tenant domain with given UUID, throw error if not found
Environment existingEnv = getEnvironment(tenantDomain, environment.getUuid());
if (existingEnv.isReadOnly()) {
String errorMessage = String.format("Failed to update Environment with UUID '%s'. Environment is read only", environment.getUuid());
throw new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.from(ExceptionCodes.READONLY_GATEWAY_ENVIRONMENT, String.format("UUID '%s'", environment.getUuid())));
}
if (!existingEnv.getName().equals(environment.getName())) {
String errorMessage = String.format("Failed to update Environment with UUID '%s'. Environment name " + "can not be changed", environment.getUuid());
throw new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.from(ExceptionCodes.READONLY_GATEWAY_ENVIRONMENT_NAME));
}
validateForUniqueVhostNames(environment);
environment.setId(existingEnv.getId());
return apiMgtDAO.updateEnvironment(environment);
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class APIAdminImpl method deleteEnvironment.
@Override
public void deleteEnvironment(String tenantDomain, String uuid) throws APIManagementException {
// check if the VHost exists in the tenant domain with given UUID, throw error if not found
Environment existingEnv = getEnvironment(tenantDomain, uuid);
if (existingEnv.isReadOnly()) {
String errorMessage = String.format("Failed to delete Environment with UUID '%s'. Environment is read only", uuid);
throw new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.from(ExceptionCodes.READONLY_GATEWAY_ENVIRONMENT, String.format("UUID '%s'", uuid)));
}
apiMgtDAO.deleteEnvironment(uuid);
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment 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.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ExternalGatewayNotifier method unDeployApi.
/**
* Undeploy APIs from external gateway
*
* @param deployAPIInGatewayEvent DeployAPIInGatewayEvent to undeploy APIs from external gateway
* @throws NotifierException if error occurs when undeploying APIs from external gateway
*/
private void unDeployApi(DeployAPIInGatewayEvent deployAPIInGatewayEvent) throws NotifierException {
boolean deleted;
Set<String> gateways = deployAPIInGatewayEvent.getGatewayLabels();
String apiId = deployAPIInGatewayEvent.getUuid();
try {
Map<String, Environment> environments = APIUtil.getEnvironments(deployAPIInGatewayEvent.getTenantDomain());
APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(deployAPIInGatewayEvent.getProvider());
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 {
deleted = deployer.undeploy(api.getId().getName(), api.getId().getVersion(), api.getContext(), environments.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());
}
}
Aggregations