Search in sources :

Example 41 with APIRevisionDeployment

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;
}
Also used : Environment(org.wso2.carbon.apimgt.api.model.Environment) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)

Example 42 with APIRevisionDeployment

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;
}
Also used : ArrayList(java.util.ArrayList) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)

Example 43 with APIRevisionDeployment

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);
    }
}
Also used : APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 44 with APIRevisionDeployment

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);
    }
}
Also used : DeployedAPIRevision(org.wso2.carbon.apimgt.api.model.DeployedAPIRevision) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 45 with APIRevisionDeployment

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);
    }
}
Also used : DeployedAPIRevision(org.wso2.carbon.apimgt.api.model.DeployedAPIRevision) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)45 ArrayList (java.util.ArrayList)20 Environment (org.wso2.carbon.apimgt.api.model.Environment)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)15 APIRevision (org.wso2.carbon.apimgt.api.model.APIRevision)12 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)11 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)10 DeployedAPIRevision (org.wso2.carbon.apimgt.api.model.DeployedAPIRevision)10 APIRevisionDeploymentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO)10 Connection (java.sql.Connection)9 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 HashSet (java.util.HashSet)8 LinkedHashSet (java.util.LinkedHashSet)8 HashMap (java.util.HashMap)6 Response (javax.ws.rs.core.Response)6 API (org.wso2.carbon.apimgt.api.model.API)6 APIStateChangeResponse (org.wso2.carbon.apimgt.api.model.APIStateChangeResponse)6 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)6 List (java.util.List)5