Search in sources :

Example 31 with APIRevisionDeployment

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

the class ApiProductsApiServiceImpl method getAPIProductRevisionDeployments.

@Override
public Response getAPIProductRevisionDeployments(String apiProductId, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    List<APIRevisionDeployment> apiRevisionDeploymentsList = new ArrayList<>();
    List<APIRevision> apiRevisions = apiProvider.getAPIRevisions(apiProductId);
    for (APIRevision apiRevision : apiRevisions) {
        List<APIRevisionDeployment> apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeploymentList(apiRevision.getRevisionUUID());
        for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsResponse) {
            apiRevisionDeploymentsList.add(apiRevisionDeployment);
        }
    }
    List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
    for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsList) {
        apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
    }
    return Response.ok().entity(apiRevisionDeploymentDTOS).build();
}
Also used : APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) ArrayList(java.util.ArrayList) APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 32 with APIRevisionDeployment

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

the class ApisApiServiceImpl method getAPIRevisionDeployments.

/**
 * Get revision deployment list
 *
 * @param apiId             UUID of the API
 * @param messageContext    message context object
 * @return response with 200 status code
 */
@Override
public Response getAPIRevisionDeployments(String apiId, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    List<APIRevisionDeployment> apiRevisionDeploymentsList = apiProvider.getAPIRevisionsDeploymentList(apiId);
    List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
    for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsList) {
        apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
    }
    return Response.ok().entity(apiRevisionDeploymentDTOS).build();
}
Also used : APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO) ArrayList(java.util.ArrayList) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 33 with APIRevisionDeployment

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

the class ApisApiServiceImpl method updateAPIDeployment.

@Override
public Response updateAPIDeployment(String apiId, String deploymentId, APIRevisionDeploymentDTO apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    // validate if api exists
    APIInfo apiInfo = validateAPIExistence(apiId);
    // validate API update operation permitted based on the LC state
    validateAPIOperationsPerLC(apiInfo.getStatus().toString());
    String revisionId = apIRevisionDeploymentDTO.getRevisionUuid();
    String decodedDeploymentName;
    if (deploymentId != null) {
        try {
            decodedDeploymentName = new String(Base64.getUrlDecoder().decode(deploymentId), StandardCharsets.UTF_8);
        } catch (IllegalArgumentException e) {
            throw new APIMgtResourceNotFoundException("deployment with " + deploymentId + " not found", ExceptionCodes.from(ExceptionCodes.EXISTING_DEPLOYMENT_NOT_FOUND, deploymentId));
        }
    } else {
        throw new APIMgtResourceNotFoundException("deployment id not found", ExceptionCodes.from(ExceptionCodes.DEPLOYMENT_ID_NOT_FOUND));
    }
    APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
    apiRevisionDeployment.setRevisionUUID(revisionId);
    apiRevisionDeployment.setDeployment(decodedDeploymentName);
    apiRevisionDeployment.setVhost(apIRevisionDeploymentDTO.getVhost());
    apiRevisionDeployment.setDisplayOnDevportal(apIRevisionDeploymentDTO.isDisplayOnDevportal());
    apiProvider.updateAPIDisplayOnDevportal(apiId, revisionId, apiRevisionDeployment);
    APIRevisionDeployment apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeployment(decodedDeploymentName, revisionId);
    APIRevisionDeploymentDTO apiRevisionDeploymentDTO = APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeploymentsResponse);
    Response.Status status = Response.Status.OK;
    return Response.status(status).entity(apiRevisionDeploymentDTO).build();
}
Also used : HttpResponse(org.apache.http.HttpResponse) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) Response(javax.ws.rs.core.Response) APIDefinitionValidationResponse(org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 34 with APIRevisionDeployment

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

the class ExportUtils method addGatewayEnvironmentsToArchive.

/**
 * Retrieve the deployed gateway environments and store those in the archive directory.
 *
 * @param archivePath  File path to export the endpoint certificates
 * @param apiID        UUID of the API/ API Product
 * @param exportFormat Export format of file
 * @param apiProvider  API Provider
 * @throws APIImportExportException If an error occurs while exporting gateway environments
 */
public static void addGatewayEnvironmentsToArchive(String archivePath, String apiID, ExportFormat exportFormat, APIProvider apiProvider) throws APIManagementException {
    try {
        List<APIRevisionDeployment> deploymentsList = apiProvider.getAPIRevisionDeploymentList(apiID);
        JsonArray deploymentsArray = new JsonArray();
        for (APIRevisionDeployment deployment : deploymentsList) {
            JsonObject deploymentObject = new JsonObject();
            // Do not set vhost in deployment environment file when export API (or API Project)
            // So when importing the exported API, the default vhost of the new environment is selected.
            deploymentObject.addProperty(ImportExportConstants.DEPLOYMENT_NAME, deployment.getDeployment());
            deploymentObject.addProperty(ImportExportConstants.DISPLAY_ON_DEVPORTAL_OPTION, deployment.isDisplayOnDevportal());
            deploymentsArray.add(deploymentObject);
        }
        if (deploymentsArray.size() > 0) {
            CommonUtil.writeDtoToFile(archivePath + ImportExportConstants.DEPLOYMENT_INFO_LOCATION, exportFormat, ImportExportConstants.TYPE_DEPLOYMENT_ENVIRONMENTS, deploymentsArray);
        }
    } catch (APIImportExportException e) {
        throw new APIManagementException("Error in converting deployment environment details to JSON object in API: " + apiID, e);
    } catch (IOException e) {
        throw new APIManagementException("Error while saving deployment environment details for API: " + apiID + " as YAML", e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) JsonObject(com.google.gson.JsonObject) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) IOException(java.io.IOException)

Example 35 with APIRevisionDeployment

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

the class ApiMgtDAO method getRevisionsListByAPIUUID.

/**
 * Get revision details by providing revision UUID
 *
 * @return revisions List object
 * @throws APIManagementException if an error occurs while retrieving revision details
 */
public List<APIRevision> getRevisionsListByAPIUUID(String apiUUID) throws APIManagementException {
    List<APIRevision> revisionList = new ArrayList<>();
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.GET_REVISIONS_BY_API_UUID)) {
        statement.setString(1, apiUUID);
        try (ResultSet rs = statement.executeQuery()) {
            while (rs.next()) {
                APIRevision apiRevision = new APIRevision();
                apiRevision.setId(rs.getInt("ID"));
                apiRevision.setApiUUID(apiUUID);
                apiRevision.setRevisionUUID(rs.getString("REVISION_UUID"));
                apiRevision.setDescription(rs.getString("DESCRIPTION"));
                apiRevision.setCreatedTime(rs.getString("CREATED_TIME"));
                apiRevision.setCreatedBy(rs.getString("CREATED_BY"));
                apiRevision.setApiRevisionDeploymentList(new ArrayList<>());
                revisionList.add(apiRevision);
            }
        }
    } catch (SQLException e) {
        handleException("Failed to get revision details for API UUID: " + apiUUID, e);
    }
    // adding deployment info to revision objects
    List<APIRevisionDeployment> allAPIRevisionDeploymentList = getAPIRevisionDeploymentByApiUUID(apiUUID);
    for (APIRevisionDeployment apiRevisionDeployment : allAPIRevisionDeploymentList) {
        for (APIRevision apiRevision : revisionList) {
            if (apiRevision.getRevisionUUID().equals(apiRevisionDeployment.getRevisionUUID())) {
                apiRevision.getApiRevisionDeploymentList().add(apiRevisionDeployment);
                break;
            }
        }
    }
    return revisionList;
}
Also used : DeployedAPIRevision(org.wso2.carbon.apimgt.api.model.DeployedAPIRevision) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) 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