Search in sources :

Example 36 with APIRevisionDeployment

use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.

the class ApiMgtDAO method removeAPIRevisionDeployment.

/**
 * Remove an API revision Deployment mapping record to the database
 *
 * @param apiUUID          uuid of the revision
 * @param deployments content of the revision deployment mapping objects
 * @throws APIManagementException if an error occurs when adding a new API revision
 */
public void removeAPIRevisionDeployment(String apiUUID, Set<APIRevisionDeployment> deployments) throws APIManagementException {
    try (Connection connection = APIMgtDBUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            // Remove an entry from AM_DEPLOYMENT_REVISION_MAPPING table
            PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.REMOVE_API_REVISION_DEPLOYMENT_MAPPING);
            for (APIRevisionDeployment deployment : deployments) {
                statement.setString(1, deployment.getDeployment());
                statement.setString(2, deployment.getRevisionUUID());
                statement.addBatch();
            }
            statement.executeBatch();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw e;
        }
    } catch (SQLException e) {
        handleException("Failed to remove API Revision Deployment Mapping entry for API UUID " + apiUUID, e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)

Example 37 with APIRevisionDeployment

use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.

the class ApiMgtDAO method removeAPIRevisionDeployment.

/**
 * Remove an API revision Deployment mapping record to the database
 *
 * @param apiRevisionId          uuid of the revision
 * @param apiRevisionDeployments content of the revision deployment mapping objects
 * @throws APIManagementException if an error occurs when adding a new API revision
 */
public void removeAPIRevisionDeployment(String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeployments) throws APIManagementException {
    try (Connection connection = APIMgtDBUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            // Remove an entry from AM_DEPLOYMENT_REVISION_MAPPING table
            PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.REMOVE_API_REVISION_DEPLOYMENT_MAPPING);
            for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeployments) {
                statement.setString(1, apiRevisionDeployment.getDeployment());
                statement.setString(2, apiRevisionId);
                statement.addBatch();
            }
            statement.executeBatch();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            handleException("Failed to remove API Revision Deployment Mapping entry for Revision UUID " + apiRevisionId, e);
        }
    } catch (SQLException e) {
        handleException("Failed to remove API Revision Deployment Mapping entry for Revision UUID " + apiRevisionId, e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)

Example 38 with APIRevisionDeployment

use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIRevisionDeploymenttoDTO.

public static APIRevisionDeploymentDTO fromAPIRevisionDeploymenttoDTO(APIRevisionDeployment model) throws APIManagementException {
    APIRevisionDeploymentDTO apiRevisionDeploymentDTO = new APIRevisionDeploymentDTO();
    apiRevisionDeploymentDTO.setName(model.getDeployment());
    apiRevisionDeploymentDTO.setVhost(model.getVhost());
    if (model.getRevisionUUID() != null) {
        apiRevisionDeploymentDTO.setRevisionUuid(model.getRevisionUUID());
    }
    apiRevisionDeploymentDTO.setDisplayOnDevportal(model.isDisplayOnDevportal());
    if (model.getDeployedTime() != null) {
        try {
            apiRevisionDeploymentDTO.setDeployedTime(parseStringToDate(model.getDeployedTime()));
        } catch (java.text.ParseException e) {
            throw new APIManagementException("Error while parsing the deployed time:" + model.getDeployedTime(), e);
        }
    }
    if (model.getSuccessDeployedTime() != null) {
        try {
            apiRevisionDeploymentDTO.setSuccessDeployedTime(parseStringToDate(model.getSuccessDeployedTime()));
        } catch (java.text.ParseException e) {
            throw new APIManagementException("Error while parsing the successfully deployed time:" + model.getSuccessDeployedTime(), e);
        }
    }
    return apiRevisionDeploymentDTO;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO)

Example 39 with APIRevisionDeployment

use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIRevisiontoDTO.

public static APIRevisionDTO fromAPIRevisiontoDTO(APIRevision model) throws APIManagementException {
    APIRevisionDTO apiRevisionDTO = new APIRevisionDTO();
    apiRevisionDTO.setId(model.getRevisionUUID());
    String key = "Revision " + model.getId();
    apiRevisionDTO.setDisplayName(key);
    apiRevisionDTO.setDescription(model.getDescription());
    if (model.getCreatedTime() != null) {
        try {
            apiRevisionDTO.setCreatedTime(parseStringToDate(model.getCreatedTime()));
        } catch (java.text.ParseException e) {
            throw new APIManagementException("Error while parsing the created time:" + model.getCreatedTime(), e);
        }
    }
    APIRevisionAPIInfoDTO apiRevisionAPIInfoDTO = new APIRevisionAPIInfoDTO();
    apiRevisionAPIInfoDTO.setId(model.getApiUUID());
    apiRevisionDTO.setApiInfo(apiRevisionAPIInfoDTO);
    List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
    if (model.getApiRevisionDeploymentList() != null) {
        for (APIRevisionDeployment apiRevisionDeployment : model.getApiRevisionDeploymentList()) {
            apiRevisionDeploymentDTOS.add(fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
        }
    }
    apiRevisionDTO.setDeploymentInfo(apiRevisionDeploymentDTOS);
    return apiRevisionDTO;
}
Also used : APIRevisionAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionAPIInfoDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO) ArrayList(java.util.ArrayList) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIRevisionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO)

Example 40 with APIRevisionDeployment

use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.

the class SolaceNotifierUtils method getThirdPartySolaceBrokerEnvironmentNameOfAPIDeployment.

/**
 * Get third party Solace broker environment Name for API deployment
 *
 * @param api Name of the API
 * @return String of the name of environment in Solace broker
 * @throws APIManagementException is error occurs when getting the name of the environment name
 */
private String getThirdPartySolaceBrokerEnvironmentNameOfAPIDeployment(API api) throws APIManagementException {
    apiMgtDAO = ApiMgtDAO.getInstance();
    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())) {
                return environmentName;
            }
        }
    }
    return null;
}
Also used : Environment(org.wso2.carbon.apimgt.api.model.Environment) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)

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