use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class APIProviderImpl method updateAPIProductDisplayOnDevportal.
@Override
public void updateAPIProductDisplayOnDevportal(String apiProductId, String apiRevisionId, APIRevisionDeployment apiRevisionDeployment) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiProductId);
if (apiProductIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiProductId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiProductId));
}
APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
if (apiRevision == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
}
List<APIRevisionDeployment> currentApiRevisionDeploymentList = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiProductId);
Set<APIRevisionDeployment> environmentsToUpdate = new HashSet<>();
for (APIRevisionDeployment currentapiRevisionDeployment : currentApiRevisionDeploymentList) {
if (StringUtils.equalsIgnoreCase(currentapiRevisionDeployment.getDeployment(), apiRevisionDeployment.getDeployment())) {
environmentsToUpdate.add(apiRevisionDeployment);
}
}
if (environmentsToUpdate.size() > 0) {
apiMgtDAO.updateAPIRevisionDeployment(apiProductId, environmentsToUpdate);
} else {
throw new APIMgtResourceNotFoundException("deployment with " + apiRevisionDeployment.getDeployment() + " not found", ExceptionCodes.from(ExceptionCodes.EXISTING_DEPLOYMENT_NOT_FOUND, apiRevisionDeployment.getDeployment()));
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class APIProviderImpl method populateRevisionInformation.
private void populateRevisionInformation(API api, String revisionUUID) throws APIManagementException {
APIRevision apiRevision = apiMgtDAO.checkAPIUUIDIsARevisionUUID(revisionUUID);
if (apiRevision != null && !StringUtils.isEmpty(apiRevision.getApiUUID())) {
api.setRevision(true);
api.setRevisionedApiId(apiRevision.getApiUUID());
api.setRevisionId(apiRevision.getId());
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class APIProviderImpl method undeployAPIProductRevisionDeployment.
@Override
public void undeployAPIProductRevisionDeployment(String apiProductId, String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeployments) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiProductId);
if (apiProductIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiProductId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiProductId));
}
APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
if (apiRevision == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
}
APIProduct product = getAPIProductbyUUID(apiRevisionId, tenantDomain);
product.setUuid(apiProductId);
Set<String> environmentsToRemove = new HashSet<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeployments) {
environmentsToRemove.add(apiRevisionDeployment.getDeployment());
}
product.setEnvironments(environmentsToRemove);
removeFromGateway(product, tenantDomain, new HashSet<>(apiRevisionDeployments), Collections.emptySet());
apiMgtDAO.removeAPIRevisionDeployment(apiRevisionId, apiRevisionDeployments);
GatewayArtifactsMgtDAO.getInstance().removePublishedGatewayLabels(apiProductId, apiRevisionId);
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class APIProviderImpl method deployAPIRevision.
/**
* Adds a new APIRevisionDeployment to an existing API
*
* @param apiId API UUID
* @param apiRevisionId API Revision UUID
* @param apiRevisionDeployments List of APIRevisionDeployment objects
* @param organization identifier of the organization
* @throws APIManagementException if failed to add APIRevision
*/
@Override
public void deployAPIRevision(String apiId, String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeployments, String organization) throws APIManagementException {
APIIdentifier apiIdentifier = APIUtil.getAPIIdentifierFromUUID(apiId);
if (apiIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
if (apiRevision == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
}
List<APIRevisionDeployment> currentApiRevisionDeploymentList = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiId);
APIGatewayManager gatewayManager = APIGatewayManager.getInstance();
API api = getLightweightAPIByUUID(apiId, organization);
api.setRevisionedApiId(apiRevision.getRevisionUUID());
api.setRevisionId(apiRevision.getId());
api.setUuid(apiId);
api.getId().setUuid(apiId);
api.setOrganization(organization);
Set<String> environmentsToAdd = new HashSet<>();
Map<String, String> gatewayVhosts = new HashMap<>();
Set<APIRevisionDeployment> environmentsToRemove = new HashSet<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeployments) {
for (APIRevisionDeployment currentapiRevisionDeployment : currentApiRevisionDeploymentList) {
if (StringUtils.equalsIgnoreCase(currentapiRevisionDeployment.getDeployment(), apiRevisionDeployment.getDeployment())) {
environmentsToRemove.add(currentapiRevisionDeployment);
}
}
environmentsToAdd.add(apiRevisionDeployment.getDeployment());
gatewayVhosts.put(apiRevisionDeployment.getDeployment(), apiRevisionDeployment.getVhost());
}
if (environmentsToRemove.size() > 0) {
apiMgtDAO.removeAPIRevisionDeployment(apiId, environmentsToRemove);
removeFromGateway(api, environmentsToRemove, environmentsToAdd);
}
GatewayArtifactsMgtDAO.getInstance().addAndRemovePublishedGatewayLabels(apiId, apiRevisionId, environmentsToAdd, gatewayVhosts, environmentsToRemove);
apiMgtDAO.addAPIRevisionDeployment(apiRevisionId, apiRevisionDeployments);
if (environmentsToAdd.size() > 0) {
// TODO remove this to organization once the microgateway can build gateway based on organization.
gatewayManager.deployToGateway(api, tenantDomain, environmentsToAdd);
}
String publishedDefaultVersion = getPublishedDefaultVersion(apiIdentifier);
String defaultVersion = getDefaultVersion(apiIdentifier);
apiMgtDAO.updateDefaultAPIPublishedVersion(apiIdentifier);
if (publishedDefaultVersion != null) {
if (apiIdentifier.getVersion().equals(defaultVersion)) {
api.setAsPublishedDefaultVersion(true);
}
if (api.isPublishedDefaultVersion() && !apiIdentifier.getVersion().equals(publishedDefaultVersion)) {
APIIdentifier previousDefaultVersionIdentifier = new APIIdentifier(api.getId().getProviderName(), api.getId().getApiName(), publishedDefaultVersion);
sendUpdateEventToPreviousDefaultVersion(previousDefaultVersionIdentifier, organization);
}
}
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class APIProviderImpl method deleteAPIRevision.
/**
* Delete an API Revision
*
* @param apiId API UUID
* @param apiRevisionId API Revision UUID
* @param organization identifier of the organization
* @throws APIManagementException if failed to delete APIRevision
*/
@Override
public void deleteAPIRevision(String apiId, String apiRevisionId, String organization) throws APIManagementException {
APIIdentifier apiIdentifier = APIUtil.getAPIIdentifierFromUUID(apiId);
if (apiIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
if (apiRevision == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
}
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = getAPIRevisionDeploymentList(apiRevisionId);
if (apiRevisionDeploymentsResponse.size() != 0) {
String errorMessage = "Couldn't delete API revision since API revision is currently deployed to a gateway" + "." + "You need to undeploy the API Revision from the gateway before attempting deleting API Revision: " + apiRevision.getRevisionUUID();
throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.EXISTING_API_REVISION_DEPLOYMENT_FOUND, apiRevisionId));
}
apiIdentifier.setUuid(apiId);
try {
apiPersistenceInstance.deleteAPIRevision(new Organization(organization), apiIdentifier.getUUID(), apiRevision.getRevisionUUID(), apiRevision.getId());
} catch (APIPersistenceException e) {
String errorMessage = "Failed to delete registry artifacts";
throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.ERROR_DELETING_API_REVISION, apiRevision.getApiUUID()));
}
apiMgtDAO.deleteAPIRevision(apiRevision);
gatewayArtifactsMgtDAO.deleteGatewayArtifact(apiRevision.getApiUUID(), apiRevision.getRevisionUUID());
if (artifactSaver != null) {
try {
artifactSaver.removeArtifact(apiRevision.getApiUUID(), apiIdentifier.getApiName(), apiIdentifier.getVersion(), apiRevision.getRevisionUUID(), organization);
} catch (ArtifactSynchronizerException e) {
log.error("Error while deleting Runtime artifacts from artifact Store", e);
}
}
}
Aggregations