container/src/main/java/com/streamsets/datacollector/cli/sch/SchAdmin.java
public static void enableDPM(DPMInfoJson dpmInfo, Context context) throws IOException {
    Utils.checkNotNull(dpmInfo, "DPMInfo");

    String dpmBaseURL = normalizeDpmBaseURL(dpmInfo.getBaseURL());

    // Since we support enabling/Disabling DPM, first check if token already exists for the given DPM URL.
    // If token exists skip first 3 steps
    String currentDPMBaseURL = context.configuration.get(RemoteSSOService.DPM_BASE_URL_CONFIG, "");
    String currentAppAuthToken = context.configuration.get(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG, "").trim();
    if (!currentDPMBaseURL.equals(dpmBaseURL) ||  currentAppAuthToken.length() == 0) {
      // 1. Login to DPM to get user auth token
      String userAuthToken = retrieveUserToken(dpmBaseURL, dpmInfo.getUserID(), dpmInfo.getUserPassword());
      String appAuthToken = null;

      // 2. Create Data Collector application token
      Response response = null;
      try {
        Map<String, Object> newComponentJson = new HashMap<>();
        newComponentJson.put("organization", dpmInfo.getOrganization());
        newComponentJson.put("componentType", "dc");
        newComponentJson.put("numberOfComponents", 1);
        newComponentJson.put("active", true);
        response = ClientBuilder.newClient()
            .target(dpmBaseURL + "/security/rest/v1/organization/" + dpmInfo.getOrganization() + "/components")
            .register(new CsrfProtectionFilter("CSRF"))
            .request()
            .header(SSOConstants.X_USER_AUTH_TOKEN, userAuthToken)
            .put(Entity.json(newComponentJson));
        if (response.getStatus() != Response.Status.CREATED.getStatusCode()) {
          throw new RuntimeException(Utils.format("DPM Create Application Token failed, status code '{}': {}",
              response.getStatus(),
              response.readEntity(String.class)
          ));
        }

        List<Map<String, Object>> newComponent = response.readEntity(new GenericType<List<Map<String,Object>>>() {});
        if (newComponent.size() > 0) {
          appAuthToken = (String) newComponent.get(0).get("fullAuthToken");
        } else {
          throw new RuntimeException("DPM Create Application Token failed: No token data from DPM Server.");
        }

      } finally {
        if (response != null) {
          response.close();
        }
        // Logout from DPM
        logout(dpmBaseURL, userAuthToken);
      }

      // 3. Update App Token file
      updateTokenFile(context, appAuthToken);
    }

    // 4. Update dpm.properties file
    updateDpmProperties(context, dpmBaseURL, dpmInfo.getLabels(), true);
  }
public static void enableDPM(DPMInfoJson dpmInfo, Context context) throws IOException {
    Utils.checkNotNull(dpmInfo, "DPMInfo");

    String dpmBaseURL = normalizeDpmBaseURL(dpmInfo.getBaseURL());

    // Since we support enabling/Disabling DPM, first check if token already exists for the given DPM URL.
    // If token exists skip first 3 steps
    String currentDPMBaseURL = context.configuration.get(RemoteSSOService.DPM_BASE_URL_CONFIG, "");
    String currentAppAuthToken = context.configuration.get(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG, "").trim();
    if (!currentDPMBaseURL.equals(dpmBaseURL) ||  currentAppAuthToken.length() == 0) {
      // 1. Login to DPM to get user auth token
      String userAuthToken = retrieveUserToken(dpmBaseURL, dpmInfo.getUserID(), dpmInfo.getUserPassword());
      String appAuthToken = null;

      // 2. Create Data Collector application token
      Response response = null;
      try {
        Map<String, Object> newComponentJson = new HashMap<>();
        newComponentJson.put("organization", dpmInfo.getOrganization());
        newComponentJson.put("componentType", "dc");
        newComponentJson.put("numberOfComponents", 1);
        newComponentJson.put("active", true);
        response = ClientBuilder.newClient()
            .target(dpmBaseURL + "/security/rest/v1/organization/" + dpmInfo.getOrganization() + "/components")
            .register(new CsrfProtectionFilter("CSRF"))
            .request()
            .header(SSOConstants.X_USER_AUTH_TOKEN, userAuthToken)
            .put(Entity.json(newComponentJson));
        if (response.getStatus() != Response.Status.CREATED.getStatusCode()) {
          throw new RuntimeException(Utils.format("DPM Create Application Token failed, status code '{}': {}",
              response.getStatus(),
              response.readEntity(String.class)
          ));
        }

        List<Map<String, Object>> newComponent = response.readEntity(new GenericType<List<Map<String,Object>>>() {});
        if (newComponent.size() > 0) {
          appAuthToken = (String) newComponent.get(0).get("fullAuthToken");
        } else {
          throw new RuntimeException("DPM Create Application Token failed: No token data from DPM Server.");
        }

      } finally {
        if (response != null) {
          response.close();
        }
        // Logout from DPM
        logout(dpmBaseURL, userAuthToken);
      }

      // 3. Update App Token file
      updateTokenFile(context, appAuthToken);
    }

    // 4. Update dpm.properties file
    updateDpmProperties(context, dpmBaseURL, dpmInfo.getLabels(), true);
  }
public static void enableDPM ( DPMInfoJson dpmInfo , Context context ) throws IOException { Utils . checkNotNull ( dpmInfo , "DPMInfo" ) ; String dpmBaseURL = normalizeDpmBaseURL ( dpmInfo . getBaseURL ( ) ) ; // Since we support enabling/Disabling DPM, first check if token already exists for the given DPM URL. // If token exists skip first 3 steps String currentDPMBaseURL = context . configuration . get ( RemoteSSOService . DPM_BASE_URL_CONFIG , "" ) ; String currentAppAuthToken = context . configuration . get ( RemoteSSOService . SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG , "" ) . trim ( ) ; if ( ! currentDPMBaseURL . equals ( dpmBaseURL ) || currentAppAuthToken . length ( ) == 0 ) { // 1. Login to DPM to get user auth token String userAuthToken = retrieveUserToken ( dpmBaseURL , dpmInfo . getUserID ( ) , dpmInfo . getUserPassword ( ) ) ; String appAuthToken = null ; // 2. Create Data Collector application token Response response = null ; try { Map < String , Object > newComponentJson = new HashMap <> ( ) ; newComponentJson . put ( "organization" , dpmInfo . getOrganization ( ) ) ; newComponentJson . put ( "componentType" , "dc" ) ; newComponentJson . put ( "numberOfComponents" , 1 ) ; newComponentJson . put ( "active" , true ) ; response = ClientBuilder . newClient ( ) . target ( dpmBaseURL + "/security/rest/v1/organization/" + dpmInfo . getOrganization ( ) + "/components" ) . register ( new CsrfProtectionFilter ( "CSRF" ) ) . request ( ) . header ( SSOConstants . X_USER_AUTH_TOKEN , userAuthToken ) . put ( Entity . json ( newComponentJson ) ) ; if ( response . getStatus ( ) != Response . Status . CREATED . getStatusCode ( ) ) { throw new RuntimeException ( Utils . format ( "DPM Create Application Token failed, status code '{}': {}" , response . getStatus ( ) , response . readEntity ( String . class ) ) ) ; } List < Map < String , Object > > newComponent = response . readEntity ( new GenericType < List < Map < String , Object > > > ( ) { } ) ; if ( newComponent . size ( ) > 0 ) { appAuthToken = ( String ) newComponent . get ( 0 ) . get ( "fullAuthToken" ) ; } else { throw new RuntimeException ( "DPM Create Application Token failed: No token data from DPM Server." ) ; } } finally { if ( response != null ) { response . close ( ) ; } // Logout from DPM logout ( dpmBaseURL , userAuthToken ) ; } // 3. Update App Token file updateTokenFile ( context , appAuthToken ) ; } // 4. Update dpm.properties file updateDpmProperties ( context , dpmBaseURL , dpmInfo . getLabels ( ) , true ) ; }
Enable Control Hub on this Data Collector.
Enable Control Hub on this Data Collector .