Search in sources :

Example 31 with ServiceModel

use of org.apache.knox.gateway.topology.discovery.cm.ServiceModel in project knox by apache.

the class ZeppelinServiceModelGenerator method generateService.

@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException {
    String hostname = role.getHostRef().getHostname();
    String scheme;
    String port;
    if (isSSL(roleConfig)) {
        scheme = "https";
        port = getSSLPort(roleConfig);
    } else {
        scheme = "http";
        port = getPort(roleConfig);
    }
    ServiceModel model = createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s", scheme, hostname, port));
    model.addRoleProperty(getRoleType(), SSL_ENABLED, getRoleConfigValue(roleConfig, SSL_ENABLED));
    model.addRoleProperty(getRoleType(), SERVER_PORT, getPort(roleConfig));
    model.addRoleProperty(getRoleType(), SERVER_SSL_PORT, getSSLPort(roleConfig));
    return model;
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel)

Example 32 with ServiceModel

use of org.apache.knox.gateway.topology.discovery.cm.ServiceModel in project knox by apache.

the class ZeppelinWSServiceModelGenerator method generateService.

@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) {
    String hostname = role.getHostRef().getHostname();
    String scheme;
    String port;
    if (isSSL(roleConfig)) {
        scheme = "wss";
        port = getSSLPort(roleConfig);
    } else {
        scheme = "ws";
        port = getPort(roleConfig);
    }
    ServiceModel model = createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s/ws", scheme, hostname, port));
    model.addRoleProperty(getRoleType(), SSL_ENABLED, getRoleConfigValue(roleConfig, SSL_ENABLED));
    model.addRoleProperty(getRoleType(), SERVER_PORT, getPort(roleConfig));
    model.addRoleProperty(getRoleType(), SERVER_SSL_PORT, getSSLPort(roleConfig));
    return model;
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel)

Example 33 with ServiceModel

use of org.apache.knox.gateway.topology.discovery.cm.ServiceModel in project knox by apache.

the class AbstractURLCollectorTest method createMockServiceModel.

protected static ServiceModel createMockServiceModel(final String service, final String serviceType, final String roleType, final String url) {
    ServiceModel sm = EasyMock.createNiceMock(ServiceModel.class);
    EasyMock.expect(sm.getService()).andReturn(service).anyTimes();
    EasyMock.expect(sm.getServiceType()).andReturn(serviceType).anyTimes();
    EasyMock.expect(sm.getRoleType()).andReturn(roleType).anyTimes();
    EasyMock.expect(sm.getServiceUrl()).andReturn(url).anyTimes();
    EasyMock.replay(sm);
    return sm;
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel)

Example 34 with ServiceModel

use of org.apache.knox.gateway.topology.discovery.cm.ServiceModel in project knox by apache.

the class WebHdfsServiceModelGeneratorTest method testServiceModelMetadataWithNameService.

@Test
public void testServiceModelMetadataWithNameService() {
    final Map<String, String> serviceConfig = new HashMap<>();
    serviceConfig.put(WebHdfsServiceModelGenerator.WEBHDFS_ENABLED, "true");
    serviceConfig.put(WebHdfsServiceModelGenerator.SSL_ENABLED, "false");
    final Map<String, String> roleConfig = new HashMap<>();
    roleConfig.put(WebHdfsServiceModelGenerator.AUTOFAILOVER_ENABLED, "true");
    roleConfig.put(WebHdfsServiceModelGenerator.NN_NAMESERVICE, "myService");
    roleConfig.put(WebHdfsServiceModelGenerator.NN_PORT, "12345");
    ServiceModel generated = createServiceModel(serviceConfig, roleConfig);
    validateServiceModel(generated, serviceConfig, roleConfig, false);
    // Validate model metadata properties
    final String qualifyingProperty = ServiceModel.QUALIFYING_SERVICE_PARAM_PREFIX + WebHdfsServiceModelGenerator.DISCOVERY_NAMESERVICE;
    Map<String, String> modelProps = generated.getQualifyingServiceParams();
    assertEquals("Expected one service model properties", 1, modelProps.size());
    assertEquals("Expected " + qualifyingProperty + " model property.", roleConfig.get(WebHdfsServiceModelGenerator.NN_NAMESERVICE), modelProps.get(qualifyingProperty));
}
Also used : HashMap(java.util.HashMap) ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel) AbstractServiceModelGeneratorTest(org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGeneratorTest) Test(org.junit.Test)

Example 35 with ServiceModel

use of org.apache.knox.gateway.topology.discovery.cm.ServiceModel in project knox by apache.

the class SolrServiceModelGeneratorTest method testServiceModelMetadata.

@Test
public void testServiceModelMetadata() {
    final Map<String, String> serviceConfig = new HashMap<>();
    serviceConfig.put(SolrServiceModelGenerator.USE_SSL, "false");
    final Map<String, String> roleConfig = new HashMap<>();
    roleConfig.put(SolrServiceModelGenerator.HTTP_PORT, "2468");
    roleConfig.put(SolrServiceModelGenerator.HTTPS_PORT, "1357");
    ServiceModel generated = createServiceModel(serviceConfig, roleConfig);
    validateServiceModel(generated, serviceConfig, roleConfig);
    // Validate model metadata properties
    final String serviceNameQualifier = QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_NAME;
    final String displayNameQualifier = QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_DISPLAY_NAME;
    Map<String, String> modelProps = generated.getQualifyingServiceParams();
    assertEquals("Expected two service model properties", 2, modelProps.size());
    assertEquals("Expected " + serviceNameQualifier + " model property.", getServiceType() + "-1", modelProps.get(serviceNameQualifier));
    assertEquals("Expected " + displayNameQualifier + " model property.", "null", modelProps.get(displayNameQualifier));
}
Also used : HashMap(java.util.HashMap) ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel) AbstractServiceModelGeneratorTest(org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGeneratorTest) Test(org.junit.Test)

Aggregations

ServiceModel (org.apache.knox.gateway.topology.discovery.cm.ServiceModel)35 HashMap (java.util.HashMap)4 AbstractServiceModelGeneratorTest (org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGeneratorTest)3 Test (org.junit.Test)3 ApiException (com.cloudera.api.swagger.client.ApiException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1