Search in sources :

Example 6 with DeployAPIInGatewayEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.

the class InMemoryAPIDeployer method reDeployAPI.

public void reDeployAPI(String apiName, String version, String tenantDomain) throws ArtifactSynchronizerException {
    SubscriptionDataStore tenantSubscriptionStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
    if (tenantSubscriptionStore != null) {
        org.wso2.carbon.apimgt.keymgt.model.entity.API retrievedAPI = tenantSubscriptionStore.getApiByNameAndVersion(apiName, version);
        if (retrievedAPI != null) {
            DeployAPIInGatewayEvent deployAPIInGatewayEvent = new DeployAPIInGatewayEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name(), tenantDomain, retrievedAPI.getApiId(), retrievedAPI.getUuid(), gatewayLabels, apiName, version, retrievedAPI.getApiProvider(), retrievedAPI.getApiType(), retrievedAPI.getContext());
            deployAPI(deployAPIInGatewayEvent);
        }
    }
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) DeployAPIInGatewayEvent(org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)

Example 7 with DeployAPIInGatewayEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.

the class InMemoryAPIDeployer method unDeployAPI.

public void unDeployAPI(DeployAPIInGatewayEvent gatewayEvent) throws ArtifactSynchronizerException {
    try {
        APIGatewayAdmin apiGatewayAdmin = new APIGatewayAdmin();
        MessageContext.setCurrentMessageContext(org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.createAxis2MessageContext());
        unDeployAPI(apiGatewayAdmin, gatewayEvent);
    } catch (AxisFault axisFault) {
        throw new ArtifactSynchronizerException("Error while unDeploying api ", axisFault);
    } finally {
        MessageContext.destroyCurrentMessageContext();
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) APIGatewayAdmin(org.wso2.carbon.apimgt.gateway.service.APIGatewayAdmin)

Example 8 with DeployAPIInGatewayEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.

the class InMemoryAPIDeployer method unDeployAPI.

public void unDeployAPI(String apiName, String version, String tenantDomain) throws ArtifactSynchronizerException {
    SubscriptionDataStore tenantSubscriptionStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
    if (tenantSubscriptionStore != null) {
        org.wso2.carbon.apimgt.keymgt.model.entity.API retrievedAPI = tenantSubscriptionStore.getApiByNameAndVersion(apiName, version);
        if (retrievedAPI != null) {
            DeployAPIInGatewayEvent deployAPIInGatewayEvent = new DeployAPIInGatewayEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name(), tenantDomain, retrievedAPI.getApiId(), retrievedAPI.getUuid(), gatewayLabels, apiName, version, retrievedAPI.getApiProvider(), retrievedAPI.getApiType(), retrievedAPI.getContext());
            unDeployAPI(deployAPIInGatewayEvent);
        }
    }
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) DeployAPIInGatewayEvent(org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)

Example 9 with DeployAPIInGatewayEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.

the class InMemoryAPIDeployer method unDeployAPI.

private void unDeployAPI(APIGatewayAdmin apiGatewayAdmin, DeployAPIInGatewayEvent gatewayEvent) throws AxisFault {
    if (gatewayArtifactSynchronizerProperties.isRetrieveFromStorageEnabled()) {
        GatewayAPIDTO gatewayAPIDTO = new GatewayAPIDTO();
        gatewayAPIDTO.setName(gatewayEvent.getName());
        gatewayAPIDTO.setVersion(gatewayEvent.getVersion());
        gatewayAPIDTO.setProvider(gatewayEvent.getProvider());
        gatewayAPIDTO.setTenantDomain(gatewayEvent.getTenantDomain());
        gatewayAPIDTO.setApiId(gatewayEvent.getUuid());
        setClientCertificatesToRemoveIntoGatewayDTO(gatewayAPIDTO);
        if (APIConstants.API_PRODUCT.equals(gatewayEvent.getApiType())) {
            APIProductIdentifier apiProductIdentifier = new APIProductIdentifier(gatewayEvent.getProvider(), gatewayEvent.getName(), gatewayEvent.getVersion());
            Set<APIEvent> associatedApis = gatewayEvent.getAssociatedApis();
            for (APIEvent associatedApi : associatedApis) {
                GatewayUtils.setCustomSequencesToBeRemoved(apiProductIdentifier, associatedApi.getUuid(), gatewayAPIDTO);
                GatewayUtils.setEndpointsToBeRemoved(apiProductIdentifier, associatedApi.getUuid(), gatewayAPIDTO);
            }
        } else {
            API api = new API(new APIIdentifier(gatewayEvent.getProvider(), gatewayEvent.getName(), gatewayEvent.getVersion()));
            if (APIConstants.APITransportType.GRAPHQL.toString().equalsIgnoreCase(gatewayEvent.getApiType())) {
                gatewayAPIDTO.setLocalEntriesToBeRemove(org.wso2.carbon.apimgt.impl.utils.GatewayUtils.addStringToList(gatewayEvent.getUuid().concat("_graphQL"), gatewayAPIDTO.getLocalEntriesToBeRemove()));
                DataHolder.getInstance().getApiToGraphQLSchemaDTOMap().remove(gatewayEvent.getUuid());
            }
            if (APIConstants.APITransportType.WS.toString().equalsIgnoreCase(gatewayEvent.getApiType())) {
                org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.setWebsocketEndpointsToBeRemoved(gatewayAPIDTO, gatewayEvent.getTenantDomain());
            } else {
                GatewayUtils.setEndpointsToBeRemoved(gatewayAPIDTO.getName(), gatewayAPIDTO.getVersion(), gatewayAPIDTO);
            }
            GatewayUtils.setCustomSequencesToBeRemoved(api, gatewayAPIDTO);
        }
        gatewayAPIDTO.setLocalEntriesToBeRemove(GatewayUtils.addStringToList(gatewayEvent.getUuid(), gatewayAPIDTO.getLocalEntriesToBeRemove()));
        apiGatewayAdmin.unDeployAPI(gatewayAPIDTO);
        DataHolder.getInstance().getApiToCertificatesMap().remove(gatewayEvent.getUuid());
        DataHolder.getInstance().removeKeyManagerToAPIMapping(gatewayAPIDTO.getApiId());
    }
}
Also used : GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIEvent) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier)

Example 10 with DeployAPIInGatewayEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent in project carbon-apimgt by wso2.

the class ExternalGatewayNotifier method deployApi.

/**
 * Deploy APIs to external gateway
 *
 * @param deployAPIInGatewayEvent DeployAPIInGatewayEvent to deploy APIs to external gateway
 * @throws NotifierException if error occurs when deploying APIs to external gateway
 */
private void deployApi(DeployAPIInGatewayEvent deployAPIInGatewayEvent) throws NotifierException {
    boolean deployed;
    Set<String> gateways = deployAPIInGatewayEvent.getGatewayLabels();
    String apiId = deployAPIInGatewayEvent.getUuid();
    try {
        Map<String, Environment> environments = APIUtil.getEnvironments(deployAPIInGatewayEvent.getTenantDomain());
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
        API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
        for (String deploymentEnv : gateways) {
            if (environments.containsKey(deploymentEnv)) {
                ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(environments.get(deploymentEnv).getProvider());
                if (deployer != null) {
                    try {
                        deployed = deployer.deploy(api, environments.get(deploymentEnv));
                        if (!deployed) {
                            throw new APIManagementException("Error while deploying API product to Solace broker");
                        }
                    } catch (DeployerException e) {
                        throw new APIManagementException(e.getMessage());
                    }
                }
            }
        }
    } catch (APIManagementException e) {
        throw new NotifierException(e.getMessage());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ExternalGatewayDeployer(org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer) Environment(org.wso2.carbon.apimgt.api.model.Environment) DeployerException(org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException) API(org.wso2.carbon.apimgt.api.model.API) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

Aggregations

DeployAPIInGatewayEvent (org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)8 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 API (org.wso2.carbon.apimgt.api.model.API)3 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)3 ArtifactSynchronizerException (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)3 APIEvent (org.wso2.carbon.apimgt.impl.notifier.events.APIEvent)3 SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)3 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 GatewayAPIDTO (org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO)2 Environment (org.wso2.carbon.apimgt.api.model.Environment)2 APIGatewayAdmin (org.wso2.carbon.apimgt.gateway.service.APIGatewayAdmin)2 ExternalGatewayDeployer (org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer)2 DeployerException (org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException)2 NotifierException (org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 AxisFault (org.apache.axis2.AxisFault)1 EndpointCertificateDeployer (org.wso2.carbon.apimgt.gateway.EndpointCertificateDeployer)1