use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method undeployAPIRevision.
@Override
public Response undeployAPIRevision(String apiId, String revisionId, String revisionNum, Boolean allEnvironments, List<APIRevisionDeploymentDTO> apIRevisionDeploymentDTOList, 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 organization = RestApiUtil.getValidatedOrganization(messageContext);
if (revisionId == null && revisionNum != null) {
revisionId = apiProvider.getAPIRevisionUUID(revisionNum, apiId);
if (revisionId == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(null).build();
}
}
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
List<APIRevisionDeployment> apiRevisionDeployments = new ArrayList<>();
if (allEnvironments) {
apiRevisionDeployments = apiProvider.getAPIRevisionDeploymentList(revisionId);
} else {
for (APIRevisionDeploymentDTO apiRevisionDeploymentDTO : apIRevisionDeploymentDTOList) {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setRevisionUUID(revisionId);
String environment = apiRevisionDeploymentDTO.getName();
if (environments.get(environment) == null) {
RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
}
apiRevisionDeployment.setDeployment(environment);
apiRevisionDeployment.setVhost(apiRevisionDeploymentDTO.getVhost());
apiRevisionDeployment.setDisplayOnDevportal(apiRevisionDeploymentDTO.isDisplayOnDevportal());
apiRevisionDeployments.add(apiRevisionDeployment);
}
}
apiProvider.undeployAPIRevisionDeployment(apiId, revisionId, apiRevisionDeployments, organization);
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeploymentList(revisionId);
List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsResponse) {
apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
}
Response.Status status = Response.Status.CREATED;
return Response.status(status).entity(apiRevisionDeploymentDTOS).build();
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIRevisionListToEndpointsList.
public static List<APIEndpointURLsDTO> fromAPIRevisionListToEndpointsList(APIDTO apidto, String organization) throws APIManagementException {
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
List<APIRevisionDeployment> revisionDeployments = apiConsumer.getAPIRevisionDeploymentListOfAPI(apidto.getId());
// custom gateway URL of tenant
Map<String, String> domains = new HashMap<>();
if (organization != null) {
domains = apiConsumer.getTenantDomainMappings(organization, APIConstants.API_DOMAIN_MAPPINGS_GATEWAY);
}
String customGatewayUrl = domains.get(APIConstants.CUSTOM_URL);
List<APIEndpointURLsDTO> endpointUrls = new ArrayList<>();
for (APIRevisionDeployment revisionDeployment : revisionDeployments) {
if (revisionDeployment.isDisplayOnDevportal()) {
// Deployed environment
Environment environment = environments.get(revisionDeployment.getDeployment());
if (environment != null) {
APIEndpointURLsDTO apiEndpointURLsDTO = fromAPIRevisionToEndpoints(apidto, environment, revisionDeployment.getVhost(), customGatewayUrl, organization);
endpointUrls.add(apiEndpointURLsDTO);
}
}
}
return endpointUrls;
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class ApiMgtDAO method updateAPIRevisionDeployment.
/**
* Update API revision Deployment mapping record
*
* @param apiUUID API UUID
* @param deployments content of the revision deployment mapping objects
* @throws APIManagementException if an error occurs when adding a new API revision
*/
public void updateAPIRevisionDeployment(String apiUUID, Set<APIRevisionDeployment> deployments) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection()) {
connection.setAutoCommit(false);
// Update an entry from AM_DEPLOYMENT_REVISION_MAPPING table
try (PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.UPDATE_API_REVISION_DEPLOYMENT_MAPPING)) {
for (APIRevisionDeployment deployment : deployments) {
statement.setBoolean(1, deployment.isDisplayOnDevportal());
statement.setString(2, deployment.getDeployment());
statement.setString(3, deployment.getRevisionUUID());
statement.addBatch();
}
statement.executeBatch();
connection.commit();
} catch (SQLException e) {
connection.rollback();
throw e;
}
} catch (SQLException e) {
handleException("Failed to update Deployment Mapping entry for API UUID " + apiUUID, e);
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class ApiMgtDAO method addAPIRevisionDeployment.
/**
* Adds 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 addAPIRevisionDeployment(String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeployments) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection()) {
try {
connection.setAutoCommit(false);
// Adding to AM_DEPLOYMENT_REVISION_MAPPING table
PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.ADD_API_REVISION_DEPLOYMENT_MAPPING);
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeployments) {
String envName = apiRevisionDeployment.getDeployment();
String vhost = apiRevisionDeployment.getVhost();
// set VHost as null, if it is the default vhost of the read only environment
statement.setString(1, apiRevisionDeployment.getDeployment());
statement.setString(2, VHostUtils.resolveIfDefaultVhostToNull(envName, vhost));
statement.setString(3, apiRevisionId);
statement.setBoolean(4, apiRevisionDeployment.isDisplayOnDevportal());
statement.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
statement.addBatch();
}
statement.executeBatch();
connection.commit();
} catch (SQLException e) {
connection.rollback();
handleException("Failed to add API Revision Deployment Mapping entry for Revision UUID " + apiRevisionId, e);
}
} catch (SQLException e) {
handleException("Failed to add API Revision Deployment Mapping entry for Revision UUID " + apiRevisionId, e);
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAPIRevisionDeploymentByNameAndRevsionID.
/**
* Get APIRevisionDeployment details by providing deployment name and revision uuid
*
* @return APIRevisionDeployment object
* @throws APIManagementException if an error occurs while retrieving revision details
*/
public APIRevisionDeployment getAPIRevisionDeploymentByNameAndRevsionID(String name, String revisionId) throws APIManagementException {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.GET_API_REVISION_DEPLOYMENT_MAPPING_BY_NAME_AND_REVISION_UUID)) {
statement.setString(1, name);
statement.setString(2, revisionId);
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
String environmentName = rs.getString("NAME");
String vhost = rs.getString("VHOST");
apiRevisionDeployment.setDeployment(environmentName);
apiRevisionDeployment.setVhost(VHostUtils.resolveIfNullToDefaultVhost(environmentName, vhost));
apiRevisionDeployment.setRevisionUUID(rs.getString("REVISION_UUID"));
apiRevisionDeployment.setDisplayOnDevportal(rs.getBoolean("DISPLAY_ON_DEVPORTAL"));
apiRevisionDeployment.setDeployedTime(rs.getString("DEPLOYED_TIME"));
}
}
} catch (SQLException e) {
handleException("Failed to get API Revision deployment mapping details for deployment name: " + name, e);
}
return apiRevisionDeployment;
}
Aggregations