Search in sources :

Example 16 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method buildConfig.

/**
 * Build configurations for Openshift client
 *
 * @throws ContainerBasedGatewayException if failed to configure Openshift client
 */
private Config buildConfig() throws ContainerBasedGatewayException {
    System.setProperty(TRY_KUBE_CONFIG, "false");
    System.setProperty(TRY_SERVICE_ACCOUNT, "true");
    ConfigBuilder configBuilder;
    if (masterURL != null) {
        configBuilder = new ConfigBuilder().withMasterUrl(masterURL);
    } else {
        throw new ContainerBasedGatewayException("Kubernetes Master URL is not provided!", ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
    }
    if (!StringUtils.isEmpty(saTokenFileName)) {
        configBuilder.withOauthToken(resolveToken("encrypted" + saTokenFileName));
    }
    return configBuilder.build();
}
Also used : ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)

Example 17 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method initImpl.

/**
 * @see ContainerBasedGatewayGenerator#initImpl(Map)
 */
@Override
void initImpl(Map<String, String> implParameters) throws ContainerBasedGatewayException {
    try {
        setValues(implParameters);
        setClient(new DefaultOpenShiftClient(buildConfig()));
    } catch (KubernetesClientException e) {
        String msg = "Error occurred while creating Default Openshift Client";
        throw new ContainerBasedGatewayException(msg, e, ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
    }
}
Also used : ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 18 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method resolveToken.

/**
 * Get the token after decrypting using {@link FileEncryptionUtility#readFromEncryptedFile(java.lang.String)}
 *
 * @return service account token
 * @throws ContainerBasedGatewayException if an error occurs while resolving the token
 */
private String resolveToken(String encryptedTokenFileName) throws ContainerBasedGatewayException {
    String token;
    try {
        String externalSATokenFilePath = System.getProperty(FileEncryptionUtility.CARBON_HOME) + FileEncryptionUtility.SECURITY_DIR + File.separator + encryptedTokenFileName;
        token = FileEncryptionUtility.getInstance().readFromEncryptedFile(externalSATokenFilePath);
    } catch (APIManagementException e) {
        String msg = "Error occurred while resolving externally stored token";
        throw new ContainerBasedGatewayException(msg, e, ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
    }
    return StringUtils.replace(token, "\n", "");
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)

Example 19 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testDeleteAPIForException.

@Test(expected = GatewayException.class)
public void testDeleteAPIForException() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    Mockito.doThrow(ContainerBasedGatewayException.class).when(containerBasedGatewayGenerator).removeContainerBasedGateway(Mockito.any(), Mockito.any());
    List<String> labels = new ArrayList<>();
    labels.add("label");
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 20 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenLabelAreEmpty.

@Test
public void testDeleteAPIWhenLabelAreEmpty() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    List<String> labels = new ArrayList<>();
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(0)).removeContainerBasedGateway("label", api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Aggregations

ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)18 Test (org.junit.Test)16 API (org.wso2.carbon.apimgt.core.models.API)15 ArrayList (java.util.ArrayList)9 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 Service (io.fabric8.kubernetes.api.model.Service)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)5 Broker (org.wso2.carbon.apimgt.core.api.Broker)5 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)4 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)3 ContainerBasedGatewayConfiguration (org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)2 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)1 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)1 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)1 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)1 LocalDateTime (java.time.LocalDateTime)1