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();
}
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();
}
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();
}
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);
}
}
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;
}
Aggregations