Search in sources :

Example 1 with ServiceModel

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

the class ClouderaManagerAPIServiceModelGenerator method generateService.

/**
 * This method functions differently than others. This method inquires the
 * discovery client and uses the CM url used by the driver (which was
 * populated by the descriptor).
 *
 * @param service Service.
 * @param serviceConfig Service config.
 * @param role Role.
 * @param roleConfig Role config.
 * @return ServiceModel for given service and role.
 * @throws ApiException Exception interacting with CM.
 */
@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException {
    final String basePath = getClient().getBasePath();
    URI uri;
    try {
        uri = new URI(basePath);
    } catch (URISyntaxException e) {
        throw new ApiException(e);
    }
    final String serviceURL = getModelType() == ServiceModel.Type.API ? String.format(Locale.getDefault(), "%s://%s:%s/api", uri.getScheme(), uri.getHost(), uri.getPort()) : String.format(Locale.getDefault(), "%s://%s:%s", uri.getScheme(), uri.getHost(), uri.getPort());
    return new ServiceModel(getModelType(), getService(), getServiceType(), getRoleType(), serviceURL);
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 2 with ServiceModel

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

the class AtlasServiceModelGenerator 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;
    boolean sslEnabled = Boolean.parseBoolean(getRoleConfigValue(roleConfig, SSL_ENABLED));
    if (sslEnabled) {
        scheme = "https";
        port = getRoleConfigValue(roleConfig, HTTPS_PORT);
    } else {
        scheme = "http";
        port = getRoleConfigValue(roleConfig, HTTP_PORT);
    }
    ServiceModel model = new ServiceModel(getModelType(), getService(), getServiceType(), getRoleType(), String.format(Locale.getDefault(), "%s://%s:%s", scheme, hostname, port));
    model.addRoleProperty(getRoleType(), SSL_ENABLED, getRoleConfigValue(roleConfig, SSL_ENABLED));
    model.addRoleProperty(getRoleType(), HTTPS_PORT, getRoleConfigValue(roleConfig, HTTPS_PORT));
    model.addRoleProperty(getRoleType(), HTTP_PORT, getRoleConfigValue(roleConfig, HTTP_PORT));
    return model;
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel)

Example 3 with ServiceModel

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

the class HdfsUIServiceModelGenerator 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;
    boolean sslEnabled = Boolean.parseBoolean(getServiceConfigValue(serviceConfig, SSL_ENABLED));
    if (sslEnabled) {
        scheme = "https";
        port = getRoleConfigValue(roleConfig, HTTPS_PORT);
    } else {
        scheme = "http";
        port = getRoleConfigValue(roleConfig, HTTP_PORT);
    }
    String namenodeUrl = String.format(Locale.getDefault(), "%s://%s:%s", scheme, hostname, port);
    ServiceModel model = createServiceModel(namenodeUrl);
    model.addServiceProperty(SSL_ENABLED, getServiceConfigValue(serviceConfig, SSL_ENABLED));
    model.addRoleProperty(role.getType(), HTTPS_PORT, getRoleConfigValue(roleConfig, HTTPS_PORT));
    model.addRoleProperty(role.getType(), HTTP_PORT, getRoleConfigValue(roleConfig, HTTP_PORT));
    ServiceModel parent = super.generateService(service, serviceConfig, role, roleConfig);
    addParentModelMetadata(model, parent);
    return model;
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel)

Example 4 with ServiceModel

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

the class WebHdfsServiceModelGenerator method generateService.

@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException {
    ServiceModel parent = super.generateService(service, serviceConfig, role, roleConfig);
    String serviceUrl = parent.getServiceUrl() + WEBHDFS_SUFFIX;
    ServiceModel model = createServiceModel(serviceUrl);
    model.addServiceProperty(WEBHDFS_ENABLED, getServiceConfigValue(serviceConfig, WEBHDFS_ENABLED));
    // Add parent model metadata
    addParentModelMetadata(model, parent);
    return model;
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel)

Example 5 with ServiceModel

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

the class ImpalaServiceModelGenerator method generateService.

@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException {
    String hostname = role.getHostRef().getHostname();
    boolean sslEnabled = Boolean.parseBoolean(getServiceConfigValue(serviceConfig, SSL_ENABLED));
    String scheme = sslEnabled ? "https" : "http";
    // Role config properties
    String port = getRoleConfigValue(roleConfig, HTTP_PORT);
    ServiceModel model = createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s/", scheme, hostname, port));
    model.addServiceProperty(SSL_ENABLED, getServiceConfigValue(serviceConfig, SSL_ENABLED));
    model.addRoleProperty(getRoleType(), HTTP_PORT, port);
    return model;
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel)

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