3 import com.fasterxml.jackson.databind.ObjectMapper;
5 import com.google.gson.JsonObject;
6 import json.Environment;
7 import json.response.ItemsResponse.Item;
8 import json.templateInfo.DeployTemplateConfig;
9 import json.templateInfo.TemplateInfo;
11 import utilities.IDcaeRestClient;
12 import utilities.IReport;
13 import utilities.Report;
14 import utilities.DcaeRestClient;
17 import java.net.ConnectException;
18 import java.util.Arrays;
19 import java.util.List;
23 private static final String CONFIG_FILE = "DcaeDtDeployConfigFile";
24 private static final String ENVIRONMENT_CONFIG = "environment.resource";
26 private static LoggerError errLogger = LoggerError.getInstance();
27 private static LoggerDebug debugLogger = LoggerDebug.getInstance();
30 throw new IllegalAccessError("Utility class");
33 public static void main(String[] args) {
34 System.setProperty("logback.configurationFile", "conf/logback.xml");
35 debugLogger.log("Starting VFCMT template deployment");
36 if (args.length != 2) {
37 errLogger.log("Got " + args.length + ", but expecting exactly 2 arguments ONLY!");
40 debugLogger.log("Arguments:");
41 Arrays.stream(args).forEach(arg -> debugLogger.log(arg));
43 initConfiguration(args);
44 IReport report = new Report();
46 ObjectMapper mapper = new ObjectMapper();
47 DeployTemplateConfig deployTemplateConfig = mapper.readValue(new File(System.getProperty(CONFIG_FILE, "conf/config.json")), DeployTemplateConfig.class);
48 Environment environment = mapper.readValue(new File(System.getProperty(ENVIRONMENT_CONFIG, "conf/environment.json")), Environment.class);
50 IDcaeRestClient dcaeRestClient = new DcaeRestClient(environment.getCredential());
51 dcaeRestClient.init(environment);
53 EntitiesRetriever entitiesRetriever = new EntitiesRetriever(dcaeRestClient);
54 Map<String, List<Item>> elementsByFolderNames = entitiesRetriever.getElementsByFolder();
56 TemplateContainer templateContainer = new TemplateContainer(report, dcaeRestClient, deployTemplateConfig.getTemplateInfo(), elementsByFolderNames);
57 Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap = templateContainer.getCdumps();
59 DeployTemplate deployTemplate = new DeployTemplate(report, dcaeRestClient);
60 deployTemplate.deploy(templateInfoToJsonObjectMap);
62 debugLogger.log( "VFCMT template deployment completed successfully");
63 } catch (RuntimeException e) {
64 errLogger.log("ERROR - Template deployment failed with error " + e);
65 } catch (ConnectException e) {
66 errLogger.log( "ERROR - Failed connection to server, are you on AT&T network? {}" + e);
67 } catch (IOException e) {
68 errLogger.log( "ERROR - Fatal Error! " + e);
70 debugLogger.log(report.toString());
74 private static void initConfiguration(String[] args) {
75 System.setProperty(ENVIRONMENT_CONFIG, args[0]);
76 System.setProperty(CONFIG_FILE, args[1]);