use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class APIMgtDBUtil method mergeRevisionDeploymentDTOs.
/**
* Handle connection rollback logic. Rethrow original exception so that it can be handled centrally.
* @param rs result set
* @throws SQLException sql exception
* @throws APIManagementException api management exception
*/
public static List<APIRevisionDeployment> mergeRevisionDeploymentDTOs(ResultSet rs) throws APIManagementException, SQLException {
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
Map<String, APIRevisionDeployment> uniqueSet = new HashMap<>();
while (rs.next()) {
APIRevisionDeployment apiRevisionDeployment;
String environmentName = rs.getString("NAME");
String vhost = VHostUtils.resolveIfNullToDefaultVhost(environmentName, rs.getString("VHOST"));
String revisionUuid = rs.getString("REVISION_UUID");
String uniqueKey = (environmentName != null ? environmentName : "") + (vhost != null ? vhost : "") + (revisionUuid != null ? revisionUuid : "");
if (!uniqueSet.containsKey(uniqueKey)) {
apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setDeployment(environmentName);
apiRevisionDeployment.setVhost(vhost);
apiRevisionDeployment.setRevisionUUID(revisionUuid);
apiRevisionDeployment.setDisplayOnDevportal(rs.getBoolean("DISPLAY_ON_DEVPORTAL"));
apiRevisionDeployment.setDeployedTime(rs.getString("DEPLOY_TIME"));
apiRevisionDeployment.setSuccessDeployedTime(rs.getString("DEPLOYED_TIME"));
apiRevisionDeploymentList.add(apiRevisionDeployment);
uniqueSet.put(uniqueKey, apiRevisionDeployment);
} else {
apiRevisionDeployment = uniqueSet.get(uniqueKey);
if (!apiRevisionDeployment.isDisplayOnDevportal()) {
apiRevisionDeployment.setDisplayOnDevportal(rs.getBoolean("DISPLAY_ON_DEVPORTAL"));
}
if (apiRevisionDeployment.getDeployedTime() == null) {
apiRevisionDeployment.setDeployedTime(rs.getString("DEPLOY_TIME"));
}
if (apiRevisionDeployment.getSuccessDeployedTime() == null) {
apiRevisionDeployment.setSuccessDeployedTime(rs.getString("DEPLOYED_TIME"));
}
}
}
return apiRevisionDeploymentList;
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class ExternallyDeployedApiNotifier method undeployWhenDeleting.
/**
* Undeploy APIs from external gateway when API is deleted
*
* @param apiEvent APIEvent to undeploy APIs from external gateway
* @throws NotifierException if error occurs when undeploying APIs from external gateway
*/
private void undeployWhenDeleting(APIEvent apiEvent) throws NotifierException {
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
boolean deleted;
String apiId = apiEvent.getUuid();
try {
List<APIRevisionDeployment> test = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiId);
for (APIRevisionDeployment deployment : test) {
String deploymentEnv = deployment.getDeployment();
if (gatewayEnvironments.containsKey(deploymentEnv)) {
ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(gatewayEnvironments.get(deploymentEnv).getProvider());
if (deployer != null) {
try {
deleted = deployer.undeploy(apiEvent.getApiName(), apiEvent.getApiVersion(), apiEvent.getApiContext(), gatewayEnvironments.get(deploymentEnv));
if (!deleted) {
throw new NotifierException("Error while deleting API product from Solace broker");
}
} catch (DeployerException e) {
throw new NotifierException(e.getMessage());
}
}
}
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class GatewayArtifactsMgtDAOTest method testAddGatewayAPIArtifactAndMetaData.
@Test
public void testAddGatewayAPIArtifactAndMetaData() throws APIManagementException {
String uuid = UUID.randomUUID().toString();
String name = "apiname";
String version = "1.0.0";
String revision = UUID.randomUUID().toString();
URL resource = getClass().getClassLoader().getResource("admin-PizzaShackAPI-1.0.0.zip");
File file = new File(resource.getPath());
gatewayArtifactsMgtDAO.addGatewayAPIArtifactAndMetaData(uuid, name, version, revision, "carbon.super", APIConstants.HTTP_PROTOCOL, file);
API api = new API(new APIIdentifier("test-provider", name, version));
api.setContext("/context1");
api.setContextTemplate("/context1/{version}");
api.setUUID(uuid);
apiMgtDAO.addAPI(api, -1234, "testOrg");
String gatewayAPIId = gatewayArtifactsMgtDAO.getGatewayAPIId(name, version, "carbon.super");
Assert.assertEquals(gatewayAPIId, uuid);
Map<String, String> gatewayVhosts = new HashMap<>();
gatewayVhosts.put("label1", "dev.wso2.com");
gatewayArtifactsMgtDAO.addAndRemovePublishedGatewayLabels(uuid, revision, Collections.asSet("label1"), gatewayVhosts);
List<APIRuntimeArtifactDto> artifacts = gatewayArtifactsMgtDAO.retrieveGatewayArtifactsByAPIIDAndLabel(uuid, new String[] { "label1" }, "carbon.super");
Assert.assertEquals(artifacts.size(), 1);
RuntimeArtifactDto artifact = artifacts.get(0);
Assert.assertNotNull(artifact);
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setRevisionUUID(revision);
apiRevisionDeployment.setDeployment("label1");
gatewayVhosts = new HashMap<>();
gatewayVhosts.put("label2", "prod.wso2.com");
gatewayArtifactsMgtDAO.addAndRemovePublishedGatewayLabels(uuid, revision, Collections.asSet("label2"), gatewayVhosts, Collections.asSet(apiRevisionDeployment));
artifacts = gatewayArtifactsMgtDAO.retrieveGatewayArtifactsByAPIIDAndLabel(uuid, new String[] { "label1" }, "carbon.super");
Assert.assertEquals(artifacts.size(), 0);
artifacts = gatewayArtifactsMgtDAO.retrieveGatewayArtifactsByAPIIDAndLabel(uuid, new String[] { "label2" }, "carbon.super");
Assert.assertEquals(artifacts.size(), 1);
artifact = artifacts.get(0);
Assert.assertNotNull(artifact);
}
use of org.wso2.carbon.apimgt.api.model.APIRevisionDeployment in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method deployAPIProductRevision.
@Override
public Response deployAPIProductRevision(String apiProductId, String revisionId, List<APIRevisionDeploymentDTO> apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
List<APIRevisionDeployment> apiRevisionDeployments = new ArrayList<>();
for (APIRevisionDeploymentDTO apiRevisionDeploymentDTO : apIRevisionDeploymentDTO) {
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());
if (StringUtils.isEmpty(apiRevisionDeploymentDTO.getVhost())) {
// vhost is only required when deploying an revision, not required when un-deploying a revision
// since the same scheme 'APIRevisionDeployment' is used for deploy and undeploy, handle it here.
RestApiUtil.handleBadRequest("Required field 'vhost' not found in deployment", log);
}
apiRevisionDeployment.setDisplayOnDevportal(apiRevisionDeploymentDTO.isDisplayOnDevportal());
apiRevisionDeployments.add(apiRevisionDeployment);
}
apiProvider.deployAPIProductRevision(apiProductId, revisionId, apiRevisionDeployments);
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 ApiProductsApiServiceImpl method undeployAPIProductRevision.
@Override
public Response undeployAPIProductRevision(String apiProductId, String revisionId, String revisionNumber, Boolean allEnvironments, List<APIRevisionDeploymentDTO> apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
if (revisionId == null && revisionNumber != null) {
revisionId = apiProvider.getAPIRevisionUUID(revisionNumber, apiProductId);
if (revisionId == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(null).build();
}
}
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
List<APIRevisionDeployment> apiRevisionDeployments = new ArrayList<>();
if (allEnvironments) {
apiRevisionDeployments = apiProvider.getAPIRevisionDeploymentList(revisionId);
} else {
for (APIRevisionDeploymentDTO apiRevisionDeploymentDTO : apIRevisionDeploymentDTO) {
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.undeployAPIProductRevisionDeployment(apiProductId, revisionId, apiRevisionDeployments);
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();
}
Aggregations