Search in sources :

Example 1 with JerseyClientConfig

use of com.thinkbiganalytics.rest.JerseyClientConfig in project kylo by Teradata.

the class RemoteClientRunner method register.

/**
 * Registers this Spark Shell client with the remote Kylo services server.
 */
public void register() {
    Preconditions.checkState(serverUrl != null, "Registration server is not available.");
    // Parse server address
    final URL url;
    try {
        url = new URL(serverUrl);
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Not a valid registration URL: " + serverUrl);
    }
    // Find client id and secret
    final String clientId = System.getenv("KYLO_CLIENT_ID");
    Preconditions.checkNotNull(clientId, "Environment variable is not defined: KYLO_CLIENT_ID");
    final String clientSecret = System.getenv("KYLO_CLIENT_SECRET");
    Preconditions.checkNotNull(clientSecret, "Environment variable is not defined: KYLO_CLIENT_SECRET");
    // Register with server
    final char[] keystorePasswordChars = (keystorePassword != null) ? keystorePassword.toCharArray() : null;
    final JerseyClientConfig config = new JerseyClientConfig(url.getHost(), clientId, clientSecret.toCharArray(), url.getProtocol().equalsIgnoreCase("https"), false, keystorePath, keystorePasswordChars);
    config.setPort(url.getPort() > 0 ? url.getPort() : url.getDefaultPort());
    final JerseyRestClient client = getRestClient(config);
    final String hostName = getHostName();
    log.info("Registering client {} at {}:{} with server {}.", clientId, hostName, localPort, serverUrl);
    final Response response = client.post(url.getPath(), ImmutableMap.of("host", hostName, "port", localPort));
    if (response != null && response.getStatus() >= 200 && response.getStatus() < 300) {
        log.info("Successfully registered client.");
    } else {
        log.info("Registration failed with response: {}", response);
        throw new IllegalStateException("Failed to register with server");
    }
}
Also used : Response(javax.ws.rs.core.Response) MalformedURLException(java.net.MalformedURLException) JerseyClientConfig(com.thinkbiganalytics.rest.JerseyClientConfig) URL(java.net.URL) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient)

Example 2 with JerseyClientConfig

use of com.thinkbiganalytics.rest.JerseyClientConfig in project kylo by Teradata.

the class KyloRestProvenanceEventService method configure.

@Override
public void configure(Map<String, String> params) {
    String host = params.get(HOST_CONFIG);
    char[] pass = null;
    if (params.containsKey(PASSWORD_CONFIG)) {
        pass = params.get(PASSWORD_CONFIG).toCharArray();
    }
    String port = params.get(PORT_CONFIG);
    String username = params.get(USERNAME_CONFIG);
    JerseyClientConfig jerseyClientConfig = new JerseyClientConfig(host, username, pass);
    if (StringUtils.isNotBlank(port)) {
        jerseyClientConfig.setPort(Integer.valueOf(port));
    }
    if (params.containsKey(TRUSTSTORE_PATH_CONFIG)) {
        jerseyClientConfig.setTruststorePath(params.get(TRUSTSTORE_PATH_CONFIG));
    }
    if (params.containsKey(TRUSTSTORE_PASSWORD_CONFIG)) {
        jerseyClientConfig.setTruststorePassword(params.get(TRUSTSTORE_PASSWORD_CONFIG).toCharArray());
    }
    if (params.containsKey(TRUSTSTORE_TYPE_CONFIG)) {
        jerseyClientConfig.setTrustStoreType(params.get(TRUSTSTORE_TYPE_CONFIG));
    }
    if (params.containsKey(KEYSTORE_ON_CLASSPATH_CONFIG)) {
        jerseyClientConfig.setKeystoreOnClasspath(BooleanUtils.toBoolean(params.get(KEYSTORE_ON_CLASSPATH_CONFIG)));
    }
    if (params.containsKey(KEYSTORE_PATH_CONFIG)) {
        jerseyClientConfig.setKeystorePath(params.get(KEYSTORE_PATH_CONFIG));
    }
    if (params.containsKey(KEYSTORE_PASSWORD_CONFIG)) {
        jerseyClientConfig.setKeystorePassword(params.get(KEYSTORE_PASSWORD_CONFIG).toCharArray());
    }
    if (params.containsKey(KEYSTORE_TYPE_CONFIG)) {
        jerseyClientConfig.setKeystoreType(params.get(KEYSTORE_TYPE_CONFIG));
    }
    restClient = new JerseyRestClient(jerseyClientConfig);
}
Also used : JerseyClientConfig(com.thinkbiganalytics.rest.JerseyClientConfig) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient)

Example 3 with JerseyClientConfig

use of com.thinkbiganalytics.rest.JerseyClientConfig in project kylo by Teradata.

the class NifiConnectionInspection method inspect.

@Override
public InspectionStatus inspect(Configuration configuration) {
    InspectionStatus status = new InspectionStatus(false);
    JerseyRestClient restClient;
    try {
        restClient = new JerseyRestClient(jerseyClientConfig);
    } catch (Exception e) {
        status.addError(String.format("Failed to parse Nifi properties: %s. Check values of configuration properties starting with 'nifi.rest' in '%s'", e.getMessage(), configuration.getServicesConfigLocation()));
        return status;
    }
    About response;
    try {
        response = restClient.get(NIFI_API_FLOW_ABOUT, About.class);
    } catch (Exception e) {
        status.addError(String.format("Failed to connect to Nifi at '%s': %s. Check values of configuration properties starting with 'nifi.rest' in '%s'", jerseyClientConfig.getUrl(), e.getMessage(), configuration.getServicesConfigLocation()));
        return status;
    }
    String nifiVersion = response.about.version;
    status.addDescription(String.format("Successfully connected to Nifi version '%s' running at '%s'", nifiVersion, jerseyClientConfig.getUrl()));
    String nifiProfileKey = nifiVersion.substring(0, nifiVersion.lastIndexOf(".")) + ".x";
    List<String> nifiProfiles = nifiVersionsToProfiles.get(nifiProfileKey);
    String expectedNifiProfile = NIFI_V + nifiProfiles.get(nifiProfiles.size() - 1);
    List<String> profiles = configuration.getServicesProfiles();
    List<String> selectedNifiProfiles = profiles.stream().filter(profile -> profile.startsWith(NIFI_V)).collect(Collectors.toList());
    if (selectedNifiProfiles.size() == 0) {
        status.addError(String.format("Nifi profile is not set in '%s'. Add Nifi profile to '%s' property, e.g. '%s=<all-other-profiles>,%s'", configuration.getServicesConfigLocation(), SPRING_PROFILES_INCLUDE, SPRING_PROFILES_INCLUDE, expectedNifiProfile));
        return status;
    }
    if (selectedNifiProfiles.size() > 1) {
        status.addError(String.format("Found %s Nifi profiles in '%s'. Ensure only one Nifi profile is set, e.g. '%s=<all-other-profiles>,%s'", selectedNifiProfiles.size(), configuration.getServicesConfigLocation(), SPRING_PROFILES_INCLUDE, expectedNifiProfile));
        return status;
    }
    String selectedNifiProfile = selectedNifiProfiles.get(0);
    boolean isValidProfileSelected = nifiProfiles.stream().anyMatch(profile -> (NIFI_V + profile).equals(selectedNifiProfile));
    if (!isValidProfileSelected) {
        status.addError(String.format("Selected Nifi profile '%s' in '%s' doesn't match Nifi version '%s' running at '%s'. " + "Replace '%s' with '%s', eg. '%s=<all-other-profiles>,%s'", selectedNifiProfile, configuration.getServicesConfigLocation(), nifiVersion, jerseyClientConfig.getUrl(), selectedNifiProfile, expectedNifiProfile, SPRING_PROFILES_INCLUDE, expectedNifiProfile));
        return status;
    }
    status.setValid(true);
    return status;
}
Also used : Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) Arrays(java.util.Arrays) List(java.util.List) Map(java.util.Map) SPRING_PROFILES_INCLUDE(com.thinkbiganalytics.install.inspector.inspection.Configuration.SPRING_PROFILES_INCLUDE) HashMap(java.util.HashMap) JerseyClientConfig(com.thinkbiganalytics.rest.JerseyClientConfig) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient)

Example 4 with JerseyClientConfig

use of com.thinkbiganalytics.rest.JerseyClientConfig in project kylo by Teradata.

the class JerseySparkShellRestClient method getClient.

/**
 * Gets or creates a Jersey REST client for the specified Spark Shell process.
 *
 * @param process the Spark Shell process
 * @return the Jersey REST client
 */
@Nonnull
private JerseyRestClient getClient(@Nonnull final SparkShellProcess process) {
    return clients.computeIfAbsent(process, target -> {
        final JerseyClientConfig config = new JerseyClientConfig();
        config.setHost(target.getHostname());
        config.setPort(target.getPort());
        return new JerseyRestClient(config);
    });
}
Also used : JerseyClientConfig(com.thinkbiganalytics.rest.JerseyClientConfig) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Nonnull(javax.annotation.Nonnull)

Aggregations

JerseyClientConfig (com.thinkbiganalytics.rest.JerseyClientConfig)4 JerseyRestClient (com.thinkbiganalytics.rest.JerseyRestClient)4 SPRING_PROFILES_INCLUDE (com.thinkbiganalytics.install.inspector.inspection.Configuration.SPRING_PROFILES_INCLUDE)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Inject (javax.inject.Inject)1 Response (javax.ws.rs.core.Response)1 Component (org.springframework.stereotype.Component)1