Search in sources :

Example 1 with SPRING_PROFILES_INCLUDE

use of com.thinkbiganalytics.install.inspector.inspection.Configuration.SPRING_PROFILES_INCLUDE 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)

Aggregations

SPRING_PROFILES_INCLUDE (com.thinkbiganalytics.install.inspector.inspection.Configuration.SPRING_PROFILES_INCLUDE)1 JerseyClientConfig (com.thinkbiganalytics.rest.JerseyClientConfig)1 JerseyRestClient (com.thinkbiganalytics.rest.JerseyRestClient)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 Inject (javax.inject.Inject)1 Component (org.springframework.stereotype.Component)1