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();
}
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);
}
}
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", "");
}
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);
}
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);
}
Aggregations