use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method checkWhetherAPIDeployedToSolaceUsingRevision.
/**
* Check whether the given API is already deployed in the Solace using revision
*
* @param api Name of the API
* @return returns true if the given API is already deployed
* @throws APIManagementException If an error occurs when checking API product availability
*/
public static boolean checkWhetherAPIDeployedToSolaceUsingRevision(API api) throws APIManagementException {
apiMgtDAO = ApiMgtDAO.getInstance();
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(api.getUuid());
for (APIRevisionDeployment deployment : deployments) {
if (deployment.isDisplayOnDevportal()) {
String environmentName = deployment.getDeployment();
if (gatewayEnvironments.containsKey(environmentName)) {
Environment deployedEnvironment = gatewayEnvironments.get(environmentName);
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(deployedEnvironment.getProvider())) {
return true;
}
}
}
}
return false;
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method getDeployedSolaceEnvironmentsFromRevisionDeployments.
/**
* Get deployed solace environment name form the revision deployments
*
* @param api Name of the API
* @return List<ThirdPartyEnvironment> List of deployed solace environments
* @throws APIManagementException is error occurs when getting the list of solace environments
*/
public static List<Environment> getDeployedSolaceEnvironmentsFromRevisionDeployments(API api) throws APIManagementException {
apiMgtDAO = ApiMgtDAO.getInstance();
List<Environment> deployedSolaceEnvironments = new ArrayList<>();
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(api.getUuid());
for (APIRevisionDeployment deployment : deployments) {
String environmentName = deployment.getDeployment();
if (gatewayEnvironments.containsKey(environmentName)) {
Environment deployedEnvironment = gatewayEnvironments.get(environmentName);
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(deployedEnvironment.getProvider())) {
deployedSolaceEnvironments.add(deployedEnvironment);
}
}
}
return deployedSolaceEnvironments;
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class APIProviderImpl method removeFromGateway.
private void removeFromGateway(API api, Set<APIRevisionDeployment> gatewaysToRemove, Set<String> environmentsToAdd) {
Set<String> environmentsToAddSet = new HashSet<>(environmentsToAdd);
Set<String> environmentsToRemove = new HashSet<>();
for (APIRevisionDeployment apiRevisionDeployment : gatewaysToRemove) {
environmentsToRemove.add(apiRevisionDeployment.getDeployment());
}
environmentsToRemove.removeAll(environmentsToAdd);
APIGatewayManager gatewayManager = APIGatewayManager.getInstance();
gatewayManager.unDeployFromGateway(api, tenantDomain, environmentsToRemove);
if (log.isDebugEnabled()) {
String logMessage = "API Name: " + api.getId().getApiName() + ", API Version " + api.getId().getVersion() + " deleted from gateway";
log.debug(logMessage);
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class APIProviderImpl method addDeployedAPIRevision.
/**
* Adds a new APIRevisionDeployment to an existing API
*
* @param apiId API UUID
* @param apiRevisionUUID API Revision UUID
* @param deployedAPIRevisionList List of APIRevisionDeployment objects
* @throws APIManagementException if failed to add APIRevision
*/
@Override
public void addDeployedAPIRevision(String apiId, String apiRevisionUUID, List<DeployedAPIRevision> deployedAPIRevisionList) throws APIManagementException {
List<DeployedAPIRevision> currentDeployedApiRevisionList = apiMgtDAO.getDeployedAPIRevisionByApiUUID(apiId);
Set<DeployedAPIRevision> environmentsToRemove = new HashSet<>();
// Deployments to add
List<DeployedAPIRevision> environmentsToAdd = new ArrayList<>();
List<String> envNames = new ArrayList<>();
for (DeployedAPIRevision deployedAPIRevision : deployedAPIRevisionList) {
// Remove duplicate entries for same revision uuid and env from incoming list
if (!envNames.contains(deployedAPIRevision.getDeployment())) {
envNames.add(deployedAPIRevision.getDeployment());
environmentsToAdd.add(deployedAPIRevision);
// Remove old deployed-revision entries of same env and apiid from existing db records
for (DeployedAPIRevision currentapiRevisionDeployment : currentDeployedApiRevisionList) {
if (StringUtils.equalsIgnoreCase(currentapiRevisionDeployment.getDeployment(), deployedAPIRevision.getDeployment())) {
environmentsToRemove.add(currentapiRevisionDeployment);
}
}
}
}
// Discard old deployment info
if (environmentsToRemove.size() > 0) {
apiMgtDAO.removeDeployedAPIRevision(apiId, environmentsToRemove);
}
// Add new deployed revision update to db
if (deployedAPIRevisionList.size() > 0) {
apiMgtDAO.addDeployedAPIRevision(apiRevisionUUID, environmentsToAdd);
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class APIProviderImpl method deployAPIProductRevision.
@Override
public void deployAPIProductRevision(String apiProductId, String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeployments) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiProductId);
if (apiProductIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiProductId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiProductId));
}
APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
if (apiRevision == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
}
APIProduct product = getAPIProductbyUUID(apiRevisionId, tenantDomain);
product.setUuid(apiProductId);
List<APIRevisionDeployment> currentApiRevisionDeploymentList = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiProductId);
APIGatewayManager gatewayManager = APIGatewayManager.getInstance();
Set<String> environmentsToAdd = new HashSet<>();
Map<String, String> gatewayVhosts = new HashMap<>();
Set<APIRevisionDeployment> environmentsToRemove = new HashSet<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeployments) {
for (APIRevisionDeployment currentapiRevisionDeployment : currentApiRevisionDeploymentList) {
if (StringUtils.equalsIgnoreCase(currentapiRevisionDeployment.getDeployment(), apiRevisionDeployment.getDeployment())) {
environmentsToRemove.add(currentapiRevisionDeployment);
}
}
environmentsToAdd.add(apiRevisionDeployment.getDeployment());
gatewayVhosts.put(apiRevisionDeployment.getDeployment(), apiRevisionDeployment.getVhost());
}
if (environmentsToRemove.size() > 0) {
apiMgtDAO.removeAPIRevisionDeployment(apiProductId, environmentsToRemove);
removeFromGateway(product, tenantDomain, environmentsToRemove, environmentsToAdd);
}
GatewayArtifactsMgtDAO.getInstance().addAndRemovePublishedGatewayLabels(apiProductId, apiRevisionId, environmentsToAdd, gatewayVhosts, environmentsToRemove);
apiMgtDAO.addAPIRevisionDeployment(apiRevisionId, apiRevisionDeployments);
if (environmentsToAdd.size() > 0) {
gatewayManager.deployToGateway(product, tenantDomain, environmentsToAdd);
}
}
Aggregations