Search in sources :

Example 91 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testListServicesWithBothNamespaceAndCriteria.

@Test(description = "Test .listServices(Namespace, Criteria) method")
public void testListServicesWithBothNamespaceAndCriteria() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    // Include ClusterIPs
    sdKubernetes.setIncludeClusterIP(true);
    // Include ExternalNames
    sdKubernetes.setIncludeExternalNameTypeServices(true);
    Map<String, String> oneLabel = createOneLabelHashMap();
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
    Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withLabels(oneLabel)).thenReturn(baseOperation);
    Mockito.when(baseOperation.list()).thenReturn(createServiceListWithBothNamespaceAndCriteria());
    List<Endpoint> endpoints = sdKubernetes.listServices("dev", oneLabel);
    Assert.assertEquals(endpoints.size(), 2);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 92 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testListServicesWithoutCLusterIPAndExternalName.

@Test(description = "Test .listServices() method without ClusterIPs and ExternalNamesURLs")
public void testListServicesWithoutCLusterIPAndExternalName() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    // Not include ClusterIPs
    sdKubernetes.setIncludeClusterIP(false);
    // Not include ExternalNames
    sdKubernetes.setIncludeExternalNameTypeServices(false);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceList());
    Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
    List<Endpoint> endpoints = sdKubernetes.listServices();
    Assert.assertEquals(endpoints.size(), 5);
    Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 93 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testListServicesWithNamespace.

@Test(description = "Test .listServices(Namespace) method")
public void testListServicesWithNamespace() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    // Not include ClusterIPs
    sdKubernetes.setIncludeClusterIP(false);
    // Include ExternalNames
    sdKubernetes.setIncludeExternalNameTypeServices(true);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceListWithNamespace());
    Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
    List<Endpoint> endpoints = sdKubernetes.listServices("dev");
    Assert.assertEquals(endpoints.size(), 4);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 94 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.

the class MappingUtil method toEndpointListDto.

/**
 * Converts {@link Endpoint} list to {@link EndPointDTO} list
 *
 * @param endpointList {@link Endpoint} list
 * @return EndPointDTO list
 */
public static List<EndPointDTO> toEndpointListDto(List<Endpoint> endpointList) {
    List<EndPointDTO> endPointDTOList = new ArrayList<>();
    endpointList.forEach(endpoint -> endPointDTOList.add(new EndPointDTO().endpointConfig(endpoint.getEndpointConfig()).id(endpoint.getId()).type(endpoint.getType()).name(endpoint.getName()).security(endpoint.getSecurity())));
    return endPointDTOList;
}
Also used : ArrayList(java.util.ArrayList) EndPointDTO(org.wso2.carbon.apimgt.rest.api.core.dto.EndPointDTO)

Example 95 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processSecureSocketAnnotation.

/**
 * Extract key-store/trust-store file location from endpoint.
 *
 * @param endpointName          Endpoint name
 * @param secureSocketKeyValues secureSocket annotation struct
 * @return List of @{@link SecretModel} objects
 */
Set<SecretModel> processSecureSocketAnnotation(String endpointName, List<BLangRecordLiteral.BLangRecordKeyValue> secureSocketKeyValues) throws KubernetesPluginException {
    Set<SecretModel> secrets = new HashSet<>();
    String keyStoreFile = null;
    String trustStoreFile = null;
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : secureSocketKeyValues) {
        // extract file paths.
        String key = keyValue.getKey().toString();
        if ("keyStore".equals(key)) {
            keyStoreFile = extractFilePath(keyValue);
        } else if ("trustStore".equals(key)) {
            trustStoreFile = extractFilePath(keyValue);
        }
    }
    if (keyStoreFile != null && trustStoreFile != null) {
        if (getMountPath(keyStoreFile).equals(getMountPath(trustStoreFile))) {
            // trust-store and key-store mount to same path
            String keyStoreContent = readSecretFile(keyStoreFile);
            String trustStoreContent = readSecretFile(trustStoreFile);
            SecretModel secretModel = new SecretModel();
            secretModel.setName(getValidName(endpointName) + "-secure-socket");
            secretModel.setMountPath(getMountPath(keyStoreFile));
            Map<String, String> dataMap = new HashMap<>();
            dataMap.put(String.valueOf(Paths.get(keyStoreFile).getFileName()), keyStoreContent);
            dataMap.put(String.valueOf(Paths.get(trustStoreFile).getFileName()), trustStoreContent);
            secretModel.setData(dataMap);
            secrets.add(secretModel);
            return secrets;
        }
    }
    if (keyStoreFile != null) {
        String keyStoreContent = readSecretFile(keyStoreFile);
        SecretModel secretModel = new SecretModel();
        secretModel.setName(getValidName(endpointName) + "-keystore");
        secretModel.setMountPath(getMountPath(keyStoreFile));
        Map<String, String> dataMap = new HashMap<>();
        dataMap.put(String.valueOf(Paths.get(keyStoreFile).getFileName()), keyStoreContent);
        secretModel.setData(dataMap);
        secrets.add(secretModel);
    }
    if (trustStoreFile != null) {
        String trustStoreContent = readSecretFile(trustStoreFile);
        SecretModel secretModel = new SecretModel();
        secretModel.setName(getValidName(endpointName) + "-truststore");
        secretModel.setMountPath(getMountPath(trustStoreFile));
        Map<String, String> dataMap = new HashMap<>();
        dataMap.put(String.valueOf(Paths.get(trustStoreFile).getFileName()), trustStoreContent);
        secretModel.setData(dataMap);
        secrets.add(secretModel);
    }
    return secrets;
}
Also used : HashMap(java.util.HashMap) SecretModel(org.ballerinax.kubernetes.models.SecretModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) HashSet(java.util.HashSet)

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)118 Test (org.testng.annotations.Test)68 API (org.wso2.carbon.apimgt.core.models.API)58 HashMap (java.util.HashMap)55 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)50 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)46 ArrayList (java.util.ArrayList)38 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)33 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)30 Test (org.junit.Test)28 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)27 HashSet (java.util.HashSet)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)24 Map (java.util.Map)23 Response (javax.ws.rs.core.Response)22 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)21 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)20 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)19 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)17