package com.hp.ucmdb.rest.uiserver.integrationstudio.controllers.sample;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
/*
This scenario is to run full sync and then delta sync of all jobs under inactive integration points.
*/
public class JobSyncScenarioSample {
//the parameters you need to provide are serverIp, userName and password
public static void main(String[] args) throws Exception {
//get token for authentication
String serverIp = " ucmdb-11-2-40.u.cms-demo.com " ;//input
String userName = " admin " ;//input
String password = " admin " ;//input
String token = RestApiConnectionUtils.loginServer(serverIp, userName, password);//login server
if(token == null || token.length() == 0){
System.out.println( " Can not log in to the UCMDB server. Check your serverIp, userName or password! " );
return;
}
System.out.println(token);
//get details of all integration points
String getResult = RestApiConnectionUtils.getAllIntegrationPoints(token, serverIp);
JSONObject allIntegrationPoints = new JSONObject(getResult);
if(allIntegrationPoints == null){
System.out.println( " Can not get details of all integration points! " );
return;
}
//get names of all inactive integration points
List inactiveList = getAllInactiveIntegrationPoints(allIntegrationPoints);
if(inactiveList.size() == 0){
System.out.println( " No inactive integration point found! " );
return;
}
System.out.println( " The list of inactive integration points is " + inactiveList.toString());
System.out.println();
System.out.println( " Now, start to full sync! " );
//full sync all the jobs of inactive integration points
for (String integration_name: inactiveList) {
//activate an inactive integration point
if(!activeIntegrationPoint(token, serverIp, integration_name)){
System.out.println( " Failed to activate the " + integration_name + " integration point. " );
inactiveList.remove(integration_name);// remove the integration point if activation failed
continue;
}
//get all the job in this integration point
List