Search in sources :

Example 21 with ArtifactSynchronizerException

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException in project carbon-apimgt by wso2.

the class InMemoryAPIDeployer method retrieveArtifact.

private GatewayAPIDTO retrieveArtifact(String apiId, Set<String> gatewayLabels) throws ArtifactSynchronizerException {
    GatewayAPIDTO result;
    String labelString = String.join("|", gatewayLabels);
    String encodedString = Base64.encodeBase64URLSafeString(labelString.getBytes());
    if (artifactRetriever != null) {
        try {
            String gatewayRuntimeArtifact = artifactRetriever.retrieveArtifact(apiId, encodedString);
            if (StringUtils.isNotEmpty(gatewayRuntimeArtifact)) {
                result = new Gson().fromJson(gatewayRuntimeArtifact, GatewayAPIDTO.class);
            } else {
                String msg = "Error retrieving artifacts for API " + apiId + ". Storage returned null";
                log.error(msg);
                throw new ArtifactSynchronizerException(msg);
            }
        } catch (ArtifactSynchronizerException e) {
            String msg = "Error deploying " + apiId + " in Gateway";
            log.error(msg, e);
            throw new ArtifactSynchronizerException(msg, e);
        }
    } else {
        String msg = "Artifact retriever not found";
        log.error(msg);
        throw new ArtifactSynchronizerException(msg);
    }
    return result;
}
Also used : GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) Gson(com.google.gson.Gson)

Example 22 with ArtifactSynchronizerException

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException in project carbon-apimgt by wso2.

the class GoogleAnalyticsConfigDeployer method invokeService.

private CloseableHttpResponse invokeService(String endpoint, String tenantDomain) throws IOException, ArtifactSynchronizerException {
    HttpGet method = new HttpGet(endpoint);
    URL url = new URL(endpoint);
    String username = eventHubConfigurationDto.getUsername();
    String password = eventHubConfigurationDto.getPassword();
    byte[] credentials = Base64.encodeBase64((username + APIConstants.DELEM_COLON + password).getBytes(APIConstants.DigestAuthConstants.CHARSET));
    int port = url.getPort();
    String protocol = url.getProtocol();
    method.setHeader(APIConstants.AUTHORIZATION_HEADER_DEFAULT, APIConstants.AUTHORIZATION_BASIC + new String(credentials, APIConstants.DigestAuthConstants.CHARSET));
    if (tenantDomain != null) {
        method.setHeader(APIConstants.HEADER_TENANT, tenantDomain);
    }
    HttpClient httpClient = APIUtil.getHttpClient(port, protocol);
    try {
        return APIUtil.executeHTTPRequest(method, httpClient);
    } catch (APIManagementException e) {
        throw new ArtifactSynchronizerException(e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) HttpGet(org.apache.http.client.methods.HttpGet) HttpClient(org.apache.http.client.HttpClient) URL(java.net.URL)

Example 23 with ArtifactSynchronizerException

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException in project carbon-apimgt by wso2.

the class GoogleAnalyticsConfigDeployer method deploy.

public void deploy() throws APIManagementException {
    try {
        LocalEntryServiceProxy localEntryAdminClient = new LocalEntryServiceProxy(tenantDomain);
        String endpoint = baseURL + APIConstants.GA_CONFIG_RETRIEVAL_ENDPOINT;
        try (CloseableHttpResponse closeableHttpResponse = invokeService(endpoint, tenantDomain)) {
            deployAsLocalEntry(closeableHttpResponse, localEntryAdminClient);
        }
    } catch (IOException | ArtifactSynchronizerException e) {
        throw new APIManagementException("Error while deploying Google analytics configuration", e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) LocalEntryServiceProxy(org.wso2.carbon.apimgt.gateway.utils.LocalEntryServiceProxy) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Example 24 with ArtifactSynchronizerException

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException in project carbon-apimgt by wso2.

the class APIProviderImpl method addAPIProductRevision.

@Override
public String addAPIProductRevision(APIRevision apiRevision, String organization) throws APIManagementException {
    int revisionCountPerAPI = apiMgtDAO.getRevisionCountByAPI(apiRevision.getApiUUID());
    if (revisionCountPerAPI > 4) {
        String errorMessage = "Maximum number of revisions per API Product has reached. " + "Need to remove stale revision to create a new Revision for API Product with id:" + apiRevision.getApiUUID();
        throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.MAXIMUM_REVISIONS_REACHED, apiRevision.getApiUUID()));
    }
    int revisionId = apiMgtDAO.getMostRecentRevisionId(apiRevision.getApiUUID()) + 1;
    apiRevision.setId(revisionId);
    APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiRevision.getApiUUID());
    if (apiProductIdentifier == null) {
        throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiRevision.getApiUUID(), ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiRevision.getApiUUID()));
    }
    apiProductIdentifier.setUUID(apiRevision.getApiUUID());
    String revisionUUID;
    try {
        revisionUUID = apiPersistenceInstance.addAPIRevision(new Organization(tenantDomain), apiProductIdentifier.getUUID(), revisionId);
    } catch (APIPersistenceException e) {
        String errorMessage = "Failed to add revision registry artifacts";
        throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.ERROR_CREATING_API_REVISION, apiRevision.getApiUUID()));
    }
    if (StringUtils.isEmpty(revisionUUID)) {
        String errorMessage = "Failed to retrieve revision uuid";
        throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.API_REVISION_UUID_NOT_FOUND));
    }
    apiRevision.setRevisionUUID(revisionUUID);
    apiMgtDAO.addAPIProductRevision(apiRevision);
    try {
        File artifact = importExportAPI.exportAPIProduct(apiRevision.getApiUUID(), revisionUUID, true, ExportFormat.JSON, false, true, organization);
        gatewayArtifactsMgtDAO.addGatewayAPIArtifactAndMetaData(apiRevision.getApiUUID(), apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), apiRevision.getRevisionUUID(), tenantDomain, APIConstants.API_PRODUCT, artifact);
        if (artifactSaver != null) {
            artifactSaver.saveArtifact(apiRevision.getApiUUID(), apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), apiRevision.getRevisionUUID(), tenantDomain, artifact);
        }
    } catch (APIImportExportException | ArtifactSynchronizerException e) {
        throw new APIManagementException("Error while Store the Revision Artifact", ExceptionCodes.from(ExceptionCodes.API_REVISION_UUID_NOT_FOUND));
    }
    return revisionUUID;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) File(java.io.File)

Example 25 with ArtifactSynchronizerException

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException in project carbon-apimgt by wso2.

the class APIProviderImpl method deleteAPIProductRevision.

@Override
public void deleteAPIProductRevision(String apiProductId, String apiRevisionId, String organization) 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> 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));
    }
    apiProductIdentifier.setUUID(apiProductId);
    try {
        apiPersistenceInstance.deleteAPIRevision(new Organization(organization), apiProductIdentifier.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.deleteAPIProductRevision(apiRevision);
    gatewayArtifactsMgtDAO.deleteGatewayArtifact(apiRevision.getApiUUID(), apiRevision.getRevisionUUID());
    if (artifactSaver != null) {
        try {
            artifactSaver.removeArtifact(apiRevision.getApiUUID(), apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), apiRevision.getRevisionUUID(), tenantDomain);
        } catch (ArtifactSynchronizerException e) {
            log.error("Error while deleting Runtime artifacts from artifact Store", e);
        }
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) DeployedAPIRevision(org.wso2.carbon.apimgt.api.model.DeployedAPIRevision) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Aggregations

ArtifactSynchronizerException (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)22 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)12 IOException (java.io.IOException)7 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)6 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)6 Gson (com.google.gson.Gson)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)4 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)4 APIRevision (org.wso2.carbon.apimgt.api.model.APIRevision)4 APIImportExportException (org.wso2.carbon.apimgt.impl.importexport.APIImportExportException)4 File (java.io.File)3 URL (java.net.URL)3 HttpClient (org.apache.http.client.HttpClient)3 HttpGet (org.apache.http.client.methods.HttpGet)3 GatewayAPIDTO (org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO)3 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)3 InMemoryAPIDeployer (org.wso2.carbon.apimgt.gateway.InMemoryAPIDeployer)3 APIGatewayAdmin (org.wso2.carbon.apimgt.gateway.service.APIGatewayAdmin)3 DeployAPIInGatewayEvent (org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)3