summaryrefslogtreecommitdiffstats
path: root/cmso-service
diff options
context:
space:
mode:
authorJerry Flood <jflood@att.com>2019-03-13 16:32:02 -0400
committerJerry Flood <jflood@att.com>2019-03-15 16:13:30 -0400
commitc8b7020a4a181e3a491d4b8b50382df8045a6552 (patch)
tree88cc0f17b4f1f2f2581dafeda2384b30bf8543b8 /cmso-service
parent4720b950ac24eb1a9b93dba9d9bd0b7dc23f2437 (diff)
Commit 2: Define Create Optimized API
Multiple commits required due to the commit size constraint. Add initial commit utility Issue-ID: OPTFRA-457 Change-Id: Ibdc9292a6971548a4c6cdc63030cfb87c95baef3 Signed-off-by: Jerry Flood <jflood@att.com>
Diffstat (limited to 'cmso-service')
-rw-r--r--cmso-service/extra/src/main/java/org/onap/optf/utilities/OnapInitialCommit.java297
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ChangeWindow.java87
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ElementInfo.java93
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/NameValue.java98
4 files changed, 575 insertions, 0 deletions
diff --git a/cmso-service/extra/src/main/java/org/onap/optf/utilities/OnapInitialCommit.java b/cmso-service/extra/src/main/java/org/onap/optf/utilities/OnapInitialCommit.java
new file mode 100644
index 0000000..0abf963
--- /dev/null
+++ b/cmso-service/extra/src/main/java/org/onap/optf/utilities/OnapInitialCommit.java
@@ -0,0 +1,297 @@
+/*******************************************************************************
+ * Copyright 2019 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ ******************************************************************************/
+package org.onap.optf.utilities;
+/**
+ * Utility to split a single set of changes into multiple 'micro-commits'. Helpful for initial commits of new components
+ * into the repo
+ *
+ * This will
+ * - determine how many commits are necessary
+ * - create working folders and clone the repo 'N' times
+ * - do git remote add gerrit
+ * - copy each subset of files to the respective working clones
+ * - git add the new (updated?) files
+ * - git commit -m
+ *
+ * Since this is a work in progess the git commit -as and git review are still manual to double check the results
+ *
+ *
+ *
+ *
+ * This code currently assumes a repos structure that containes ONLY the files to be committed. There is no attempt
+ * to identify new/changed files to commit. Preparation of the list of files is manual.
+ *
+ * This does not make any attempt to determine if this will break the build.
+ *
+ * Caution. This code was developed and tested in Windows. WIndows paths to GIT bash, etc. are hard coded.
+ *
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.io.FilenameUtils;
+
+
+
+
+public class OnapInitialCommit
+{
+ CommandLine cmdline = null;
+ Long lpc = 1000l;
+
+ Map<String, Long> fileMap = new TreeMap<String, Long>();
+ List<List<String>> commitLists = new ArrayList<>();
+ public static void main(String []argv)
+ {
+ Options options = new Options();
+ options.addRequiredOption("r", "repoFolder", true, "Folder containing all of the files to commit.");
+ options.addRequiredOption("f", "filesFolder", true, "Folder containing all files to commit - relative to repo folder");
+ options.addRequiredOption("w", "commitReposFolder", true, "Folder where all of the commit repos are created");
+ options.addRequiredOption("c", "cloneCommand", true, "Clone with commit hooks command - with credentials");
+ options.addRequiredOption("g", "remoteAddGerrit", true, "git remote add gerrit command");
+ options.addRequiredOption("i", "issue", true, "Issue ID");
+ options.addRequiredOption("m", "message", true, "Commit message");
+ options.addRequiredOption("p", "clonePath", true, "Path created in commitRepoFolder by the clone command");
+
+ options.addOption("l", "linesPerCommit", true, "lines to commit");
+ CommandLineParser parser = new DefaultParser();
+ try {
+ CommandLine cmd = parser.parse( options, argv);
+ OnapInitialCommit oic = new OnapInitialCommit(cmd);
+ oic.execute();
+ } catch (ParseException e) {
+ System.out.println(e.getMessage());
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "OnapIntialCommit", options );
+
+ }
+ }
+
+
+ public OnapInitialCommit(CommandLine cmd)
+ {
+ cmdline = cmd;
+ }
+ private void execute()
+ {
+ buildCommitLists();
+
+ int i = 0;
+ for (List<String> list : commitLists)
+ {
+ i++;
+ commit(list, i);
+ }
+
+ }
+
+
+ private void commit(List<String> list, int i)
+ {
+ if (list.size() == 0)
+ return;
+ System.out.println("\n\n");
+ for (String name : list)
+ {
+ System.out.println(name + ":" + fileMap.get(name));
+ }
+ File cloneFolder = new File(cmdline.getOptionValue("w") + File.separator + "commit" + i);
+ cloneFolder.mkdirs();
+ cloneCode(cloneFolder, i);
+ System.out.println("\n\n");
+ File fromFolder = new File(cmdline.getOptionValue("r"));
+ List<String> filesToAdd = new ArrayList<>();
+ for (String fromFile : list)
+ {
+ String toPath = fromFile.replace(fromFolder.getAbsolutePath(), "");
+
+ Path toFile = Paths.get(cloneFolder + File.separator + "cmso" + toPath);
+ System.out.println(fromFile + ":" + toFile);
+ try {
+ toFile.toFile().mkdirs();
+ Files.copy(Paths.get(fromFile), toFile, StandardCopyOption.REPLACE_EXISTING);
+ filesToAdd.add(toPath);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ commitFiles(cloneFolder, filesToAdd, i);
+ }
+
+
+ private void cloneCode(File cloneFolder, int i)
+ {
+ String unixCloneFolder = FilenameUtils.separatorsToUnix(cloneFolder.getAbsolutePath());
+ unixCloneFolder = unixCloneFolder.replace("c:", "/c");
+ StringBuilder shell = new StringBuilder();
+ shell.append("cd \"").append(unixCloneFolder).append("\"\n");
+ shell.append("export PATH=$PATH:\"/C/Program Files/Git/mingw64/bin\"").append("\n");
+ shell.append(cmdline.getOptionValue("c")).append("\n");
+ shell.append("cd ").append(cmdline.getOptionValue("p")).append("\n");
+ shell.append(cmdline.getOptionValue("g")).append("\n");
+ File shellFile = new File("oic.sh");
+ File shellFileOut = new File("oic.log." + i);
+ try {
+ Files.write(Paths.get(shellFile.getAbsolutePath()), shell.toString().getBytes());
+ String command = "\"C:\\Program Files\\Git\\bin\\bash.exe\" -x " + shellFile.getAbsolutePath();
+
+ ProcessBuilder builder = new ProcessBuilder("C:\\Program Files\\Git\\bin\\bash.exe", "-x", shellFile.getAbsolutePath());
+ builder.redirectOutput(shellFileOut);
+ builder.redirectError(shellFileOut);
+ Process p = builder.start(); // may throw IOException
+ p.waitFor();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+ private void commitFiles(File cloneFolder, List<String> list, int i)
+ {
+ String unixCloneFolder = FilenameUtils.separatorsToUnix(cloneFolder.getAbsolutePath());
+ unixCloneFolder = unixCloneFolder.replace("c:", "/c");
+ StringBuilder shell = new StringBuilder();
+ shell.append("cd \"").append(unixCloneFolder).append("\"\n");
+ shell.append("export PATH=$PATH:\"/C/Program Files/Git/mingw64/bin\"").append("\n");
+ shell.append("cd ").append(cmdline.getOptionValue("p")).append("\n");
+ for (String name : list)
+ {
+ name = FilenameUtils.separatorsToUnix(name);
+ name = name.replaceAll("^/", "");
+ shell.append("git add ").append(name).append("\n");
+ }
+ shell.append("git commit -m \"Commit ").append(i).append(" for ").append(cmdline.getOptionValue("m"));
+ shell.append("\" -m \"Multiple commits required due to commit size limitation.\" -m \"");
+ shell.append("Issue-ID: ").append(cmdline.getOptionValue("i")).append("\"\n");
+
+ File shellFile = new File("addFiles" + i + ".sh");
+ File shellFileOut = new File("addFiles" + i + ".log");
+ try {
+ Files.write(Paths.get(shellFile.getAbsolutePath()), shell.toString().getBytes());
+ String command = "\"C:\\Program Files\\Git\\bin\\bash.exe\" -x " + shellFile.getAbsolutePath();
+
+ ProcessBuilder builder = new ProcessBuilder("C:\\Program Files\\Git\\bin\\bash.exe", "-x", shellFile.getAbsolutePath());
+ builder.redirectOutput(shellFileOut);
+ builder.redirectError(shellFileOut);
+ Process p = builder.start(); // may throw IOException
+ p.waitFor();
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+
+
+ private void buildCommitLists()
+ {
+ File files = new File(cmdline.getOptionValue("r") + File.separator + cmdline.getOptionValue("f"));
+ if (files.isDirectory())
+ {
+ buildCommitMap(files);
+ List<String> l = new ArrayList<>();
+ long size = 0;
+ for (String name : fileMap.keySet())
+ {
+ Long thisSize = fileMap.get(name);
+ System.out.println(thisSize + " : " + name);
+ if ((size + thisSize) > lpc )
+ {
+ commitLists.add(l);
+ l = new ArrayList<>();
+ size = 0;
+ }
+ size+=thisSize;
+ l.add(name);
+ }
+ commitLists.add(l);
+ }
+ }
+
+
+ private void buildCommitMap(File files)
+ {
+ for (File thisOne : files.listFiles())
+ {
+ if (thisOne.isDirectory())
+ buildCommitMap(thisOne);
+ else
+ updateMap(thisOne);
+ }
+
+ }
+
+
+ private void updateMap(File thisOne)
+ {
+ //System.out.println(thisOne.getAbsolutePath());
+ Path path = Paths.get(thisOne.getAbsolutePath());
+ long lineCount = -1;
+ Charset[] csList = {
+ StandardCharsets.UTF_8,
+ StandardCharsets.ISO_8859_1,
+ StandardCharsets.US_ASCII,
+ StandardCharsets.UTF_16,
+ };
+ for (Charset cs : csList)
+ {
+ try {
+ lineCount = Files.lines(path, cs).count();
+ if (lineCount > 1)
+ break;
+ } catch (Exception e) {
+ //System.out.println(thisOne.getAbsolutePath());
+ }
+ }
+ if (lineCount > -1)
+ {
+ fileMap.put(thisOne.getAbsolutePath(), lineCount);
+ }
+ else
+ {
+ System.out.println("Skipping " + thisOne.getAbsolutePath());
+ }
+ }
+
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ChangeWindow.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ChangeWindow.java
new file mode 100644
index 0000000..7553c87
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ChangeWindow.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso.service.rs.models.v2;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import org.springframework.format.annotation.DateTimeFormat;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "Change Window",
+ description = "Time window for which tickets are to returned")
+public class ChangeWindow implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ChangeWindow.class);
+
+ @ApiModelProperty(value = "Earliest time for which changes may begin.")
+ @DateTimeFormat(pattern="yyyy-MM-dd'T'hh:mm:ss'Z'")
+ private Date startTime;
+
+ @ApiModelProperty(value = "Latest time by which all changes must be completed.")
+ @DateTimeFormat(pattern="yyyy-MM-dd'T'hh:mm:ss'Z'")
+ private Date endTime;
+
+ public Date getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(Date startTime) {
+ this.startTime = startTime;
+ }
+
+ public Date getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(Date endTime) {
+ this.endTime = endTime;
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ElementInfo.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ElementInfo.java
new file mode 100644
index 0000000..35649ea
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/ElementInfo.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ *
+ * Copyright © 2019 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.onap.optf.cmso.service.rs.models.v2;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "Optimizer Element", description = "Element to be scheduled.")
+public class ElementInfo implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ElementInfo.class);
+
+ @ApiModelProperty(value = "Element identifier")
+ private String elementId;
+
+ @ApiModelProperty(value = "Implementation specific element data.")
+ public List<NameValue> elementData = new ArrayList<>();
+
+ @ApiModelProperty(value = "Request for be scheduled.")
+ public Object request;
+
+ public String getElementId() {
+ return elementId;
+ }
+
+ public void setElementId(String elementId) {
+ this.elementId = elementId;
+ }
+
+
+ public List<NameValue> getElementData() {
+ return elementData;
+ }
+
+ public void setElementData(List<NameValue> elementData) {
+ this.elementData = elementData;
+ }
+
+ public Object getRequest() {
+ return request;
+ }
+
+ public void setRequest(Object request) {
+ this.request = request;
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/NameValue.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/NameValue.java
new file mode 100644
index 0000000..9b71f76
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/v2/NameValue.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso.service.rs.models.v2;
+
+import java.io.Serializable;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "Name Value Data",
+ description = "Instance of a name/value")
+public class NameValue implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(NameValue.class);
+
+ public NameValue()
+ {
+
+ }
+
+ public NameValue(String name, Object value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ @ApiModelProperty(value = "Name.")
+ private String name;
+
+ @ApiModelProperty(value = "Value.")
+ private Object value;
+
+
+ public String getName() {
+ return name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public Object getValue() {
+ return value;
+ }
+
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+
+}