use of org.wso2.carbon.apimgt.api.model.DeployedAPIRevision in project carbon-apimgt by wso2.
the class APIProviderImpl method removeUnDeployedAPIRevision.
@Override
public void removeUnDeployedAPIRevision(String apiId, String apiRevisionUUID, String environment) throws APIManagementException {
Set<DeployedAPIRevision> environmentsToRemove = new HashSet<>();
environmentsToRemove.add(new DeployedAPIRevision(apiRevisionUUID, environment));
apiMgtDAO.removeDeployedAPIRevision(apiId, environmentsToRemove);
}
use of org.wso2.carbon.apimgt.api.model.DeployedAPIRevision in project carbon-apimgt by wso2.
the class ApiMgtDAO method removeDeployedAPIRevision.
/**
* Remove an deployed API revision in the database
*
* @param apiUUID uuid of the revision
* @param deployments content of the revision deployment mapping objects
* @throws APIManagementException if an error occurs when adding a new API revision
*/
public void removeDeployedAPIRevision(String apiUUID, Set<DeployedAPIRevision> deployments) throws APIManagementException {
if (deployments.size() > 0) {
try (Connection connection = APIMgtDBUtil.getConnection()) {
connection.setAutoCommit(false);
// Remove an entry from AM_DEPLOYED_REVISION table
try (PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.REMOVE_DEPLOYED_API_REVISION)) {
for (DeployedAPIRevision deployment : deployments) {
statement.setString(1, deployment.getDeployment());
statement.setString(2, deployment.getRevisionUUID());
statement.addBatch();
}
statement.executeBatch();
connection.commit();
} catch (SQLException e) {
connection.rollback();
handleException("Failed to remove deployed API Revision entry for API UUID " + apiUUID, e);
}
} catch (SQLException e) {
handleException("Failed to remove deployed API Revision entry for API UUID " + apiUUID, e);
}
}
}
use of org.wso2.carbon.apimgt.api.model.DeployedAPIRevision in project carbon-apimgt by wso2.
the class ApiMgtDAO method addDeployedAPIRevision.
/**
* Adds an deployed API revision to the database
*
* @param deployedAPIRevisionList content of the revision deployment mapping objects
* @throws APIManagementException if an error occurs when adding a new API revision
*/
public void addDeployedAPIRevision(String apiRevisionId, List<DeployedAPIRevision> deployedAPIRevisionList) throws APIManagementException {
if (deployedAPIRevisionList.size() > 0) {
try (Connection connection = APIMgtDBUtil.getConnection()) {
connection.setAutoCommit(false);
// Adding to AM_DEPLOYED_REVISION table
try (PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.ADD_DEPLOYED_API_REVISION)) {
for (DeployedAPIRevision deployedAPIRevision : deployedAPIRevisionList) {
String envName = deployedAPIRevision.getDeployment();
String vhost = deployedAPIRevision.getVhost();
// set VHost as null, if it is the default vhost of the read only environment
statement.setString(1, deployedAPIRevision.getDeployment());
statement.setString(2, VHostUtils.resolveIfDefaultVhostToNull(envName, vhost));
statement.setString(3, apiRevisionId);
statement.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
statement.addBatch();
}
statement.executeBatch();
connection.commit();
} catch (SQLException e) {
connection.rollback();
// handle concurrent db entry update. Fix duplicate primary key issue.
if (e.getMessage().toLowerCase().contains("primary key violation") || e.getMessage().toLowerCase().contains("duplicate entry")) {
log.debug("Duplicate entries detected for Revision UUID " + apiRevisionId + " while adding deployed API revisions", e);
} else {
handleException("Failed to add deployed API Revision for Revision UUID " + apiRevisionId, e);
}
}
} catch (SQLException e) {
handleException("Failed to add deployed API Revision for Revision UUID " + apiRevisionId, e);
}
}
}
use of org.wso2.carbon.apimgt.api.model.DeployedAPIRevision in project carbon-apimgt by wso2.
the class ApiMgtDAO method getDeployedAPIRevisionByApiUUID.
/**
* Get DeployedAPIRevision details by providing ApiUUID
*
* @return List<DeployedAPIRevision> object
* @throws APIManagementException if an error occurs while retrieving revision deployment mapping details
*/
public List<DeployedAPIRevision> getDeployedAPIRevisionByApiUUID(String apiUUID) throws APIManagementException {
List<DeployedAPIRevision> deployedAPIRevisionList = new ArrayList<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.GET_DEPLOYED_REVISION_BY_API_UUID)) {
statement.setString(1, apiUUID);
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
DeployedAPIRevision deployedAPIRevision = new DeployedAPIRevision();
String environmentName = rs.getString("NAME");
String vhost = rs.getString("VHOST");
deployedAPIRevision.setDeployment(environmentName);
deployedAPIRevision.setVhost(VHostUtils.resolveIfNullToDefaultVhost(environmentName, vhost));
deployedAPIRevision.setRevisionUUID(rs.getString("REVISION_UUID"));
deployedAPIRevision.setDeployedTime(rs.getString("DEPLOYED_TIME"));
deployedAPIRevisionList.add(deployedAPIRevision);
}
}
} catch (SQLException e) {
handleException("Failed to get deployed API Revision details for api uuid: " + apiUUID, e);
}
return deployedAPIRevisionList;
}
use of org.wso2.carbon.apimgt.api.model.DeployedAPIRevision in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method deployedAPIRevision.
public Response deployedAPIRevision(List<DeployedAPIRevisionDTO> deployedAPIRevisionDTOList, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
List<String> revisionUUIDs = new ArrayList<>();
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
for (DeployedAPIRevisionDTO deployedAPIRevisionDTO : deployedAPIRevisionDTOList) {
// get revision uuid
String revisionUUID = apiProvider.getAPIRevisionUUID(Integer.toString(deployedAPIRevisionDTO.getRevisionId()), deployedAPIRevisionDTO.getApiId());
if (revisionUUID == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(null).build();
}
if (!revisionUUIDs.contains(revisionUUID)) {
revisionUUIDs.add(revisionUUID);
Map<String, Environment> environments = APIUtil.getEnvironments(tenantDomain);
List<DeployedAPIRevision> deployedAPIRevisions = new ArrayList<>();
for (DeployedEnvInfoDTO deployedEnvInfoDTO : deployedAPIRevisionDTO.getEnvInfo()) {
DeployedAPIRevision deployedAPIRevision = new DeployedAPIRevision();
deployedAPIRevision.setRevisionUUID(revisionUUID);
String environment = deployedEnvInfoDTO.getName();
if (environments.get(environment) == null) {
RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
}
deployedAPIRevision.setDeployment(environment);
deployedAPIRevision.setVhost(deployedEnvInfoDTO.getVhost());
if (StringUtils.isEmpty(deployedEnvInfoDTO.getVhost())) {
RestApiUtil.handleBadRequest("Required field 'vhost' not found in deployment", log);
}
deployedAPIRevisions.add(deployedAPIRevision);
}
apiProvider.addDeployedAPIRevision(deployedAPIRevisionDTO.getApiId(), revisionUUID, deployedAPIRevisions);
}
}
return Response.ok().build();
}
Aggregations