diff options
author | Stone, Avi (as206k) <as206k@att.com> | 2018-04-12 15:46:31 +0300 |
---|---|---|
committer | Stone, Avi (as206k) <as206k@att.com> | 2018-04-12 15:49:38 +0300 |
commit | 5032434b101f25fa44d2e1f8dc8393e30af1ed4f (patch) | |
tree | 2dc7d37a8048e025c7412af080640da4c9a22b65 /dcaedt_tools/src/main/java/tools/Main.java | |
parent | 2205633792f95f46a02bbf8f87f0c2637265d924 (diff) |
DCAE-D be initial commit
DCAE-D be initial commit
Issue-ID: SDC-1218
Change-Id: Id18ba96c499e785aa9ac395fbaf32d57f08c281b
Signed-off-by: Stone, Avi (as206k) <as206k@att.com>
Diffstat (limited to 'dcaedt_tools/src/main/java/tools/Main.java')
-rw-r--r-- | dcaedt_tools/src/main/java/tools/Main.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/dcaedt_tools/src/main/java/tools/Main.java b/dcaedt_tools/src/main/java/tools/Main.java new file mode 100644 index 0000000..72b6e42 --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/Main.java @@ -0,0 +1,80 @@ +package tools; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.google.gson.JsonObject; +import json.Environment; +import json.response.ItemsResponse.Item; +import json.templateInfo.DeployTemplateConfig; +import json.templateInfo.TemplateInfo; + +import utilities.IDcaeRestClient; +import utilities.IReport; +import utilities.Report; +import utilities.DcaeRestClient; + +import java.io.*; +import java.net.ConnectException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class Main { + private static final String CONFIG_FILE = "DcaeDtDeployConfigFile"; + private static final String ENVIRONMENT_CONFIG = "environment.resource"; + + private static LoggerError errLogger = LoggerError.getInstance(); + private static LoggerDebug debugLogger = LoggerDebug.getInstance(); + + private Main() { + throw new IllegalAccessError("Utility class"); + } + + public static void main(String[] args) { + System.setProperty("logback.configurationFile", "conf/logback.xml"); + debugLogger.log("Starting VFCMT template deployment"); + if (args.length != 2) { + errLogger.log("Got " + args.length + ", but expecting exactly 2 arguments ONLY!"); + return; + } + debugLogger.log("Arguments:"); + Arrays.stream(args).forEach(arg -> debugLogger.log(arg)); + + initConfiguration(args); + IReport report = new Report(); + try { + ObjectMapper mapper = new ObjectMapper(); + DeployTemplateConfig deployTemplateConfig = mapper.readValue(new File(System.getProperty(CONFIG_FILE, "conf/config.json")), DeployTemplateConfig.class); + Environment environment = mapper.readValue(new File(System.getProperty(ENVIRONMENT_CONFIG, "conf/environment.json")), Environment.class); + + IDcaeRestClient dcaeRestClient = new DcaeRestClient(environment.getCredential()); + dcaeRestClient.init(environment); + + EntitiesRetriever entitiesRetriever = new EntitiesRetriever(dcaeRestClient); + Map<String, List<Item>> elementsByFolderNames = entitiesRetriever.getElementsByFolder(); + + TemplateContainer templateContainer = new TemplateContainer(report, dcaeRestClient, deployTemplateConfig.getTemplateInfo(), elementsByFolderNames); + Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap = templateContainer.getCdumps(); + + DeployTemplate deployTemplate = new DeployTemplate(report, dcaeRestClient); + deployTemplate.deploy(templateInfoToJsonObjectMap); + + debugLogger.log( "VFCMT template deployment completed successfully"); + } catch (RuntimeException e) { + errLogger.log("ERROR - Template deployment failed with error " + e); + } catch (ConnectException e) { + errLogger.log( "ERROR - Failed connection to server, are you on AT&T network? {}" + e); + } catch (IOException e) { + errLogger.log( "ERROR - Fatal Error! " + e); + } finally { + debugLogger.log(report.toString()); + } + } + + private static void initConfiguration(String[] args) { + System.setProperty(ENVIRONMENT_CONFIG, args[0]); + System.setProperty(CONFIG_FILE, args[1]); + } + + +} |