diff options
25 files changed, 1250 insertions, 367 deletions
diff --git a/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-add-uuid.sql b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-add-uuid.sql new file mode 100644 index 0000000..b11ea0a --- /dev/null +++ b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-add-uuid.sql @@ -0,0 +1,93 @@ +USE CMSO; + +-- Schedules Add UUID column +ALTER TABLE SCHEDULES ADD COLUMN uuid BINARY(16) NOT NULL FIRST; +-- Add foreign keys +ALTER TABLE DOMAIN_DATA ADD COLUMN schedules_uuid BINARY(16) NOT NULL; +ALTER TABLE SCHEDULE_APPROVALS ADD COLUMN schedules_uuid BINARY(16) NOT NULL; +ALTER TABLE CHANGE_MANAGEMENT_GROUPS ADD COLUMN schedules_uuid BINARY(16) NOT NULL; +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS ADD COLUMN schedules_uuid BINARY(16); + + + +-- CHANGE_MANAGEMENT_GROUPS Add UUID column +ALTER TABLE CHANGE_MANAGEMENT_GROUPS ADD COLUMN uuid BINARY(16) NOT NULL FIRST; +-- Foreign keys +ALTER TABLE CHANGE_MANAGEMENT_SCHEDULES ADD COLUMN change_management_group_uuid BINARY(16) NOT NULL; +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS ADD COLUMN change_management_group_uuid BINARY(16); + + +-- CHANGE_MANAGEMENT_SCHEDULES Add UUID column +ALTER TABLE CHANGE_MANAGEMENT_SCHEDULES ADD COLUMN uuid BINARY(16) NOT NULL FIRST; +-- Foreign keys + + +-- DOMAIN_DATA Add UUID column +ALTER TABLE DOMAIN_DATA ADD COLUMN uuid BINARY(16) NOT NULL FIRST; +-- Foreign keys + + +-- SCHEDULE_APPROVALS Add UUID column +ALTER TABLE SCHEDULE_APPROVALS ADD COLUMN uuid BINARY(16) NOT NULL FIRST; +-- Foreign keys + + +-- CHANGE_MANAGEMENT_CHANGE_WINDOWS Add UUID column +-- Note that change window will be related to either a schedule or a group. +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS ADD COLUMN uuid BINARY(16) NOT NULL FIRST; +-- Foreign keys + + +-- APPROVAL_TYPES Add UUID column +ALTER TABLE APPROVAL_TYPES ADD COLUMN uuid BINARY(16) NOT NULL FIRST; +-- Foreign keys +ALTER TABLE SCHEDULE_APPROVALS ADD COLUMN approval_types_uuid BINARY(16) NOT NULL; + + +-- SCHEDULE_EVENTS not used +DROP TABLE IF EXISTS SCHEDULE_EVENTS; + +SET SQL_SAFE_UPDATES = 0; + +-- ---------------------------------------------------- +-- Populate UUID in all existing uuid fields +-- ---------------------------------------------------- +UPDATE SCHEDULES SET uuid = unhex(replace(uuid(), '-', '')) where uuid is null; +UPDATE CHANGE_MANAGEMENT_GROUPS SET uuid = unhex(replace(uuid(), '-', '')) where uuid is null; +UPDATE CHANGE_MANAGEMENT_SCHEDULES SET uuid = unhex(replace(uuid(), '-', '')) where uuid is null; +UPDATE DOMAIN_DATA SET uuid = unhex(replace(uuid(), '-', '')) where uuid is null; +UPDATE SCHEDULE_APPROVALS SET uuid = unhex(replace(uuid(), '-', '')) where uuid is null; +UPDATE CHANGE_MANAGEMENT_CHANGE_WINDOWS SET uuid = unhex(replace(uuid(), '-', '')) where uuid is null; +UPDATE APPROVAL_TYPES SET uuid = unhex(replace(uuid(), '-', '')); + +-- ---------------------------------------------------- +-- SCHEDULES Update all of the foreign key columns +-- ---------------------------------------------------- +update DOMAIN_DATA set schedules_uuid = + (select distinct s.uuid from SCHEDULES s where schedules_id = s.id); +update SCHEDULE_APPROVALS set schedules_uuid = + (select distinct s.uuid from SCHEDULES s where schedules_id = s.id); +update CHANGE_MANAGEMENT_GROUPS set schedules_uuid = + (select distinct s.uuid from SCHEDULES s where schedules_id = s.id); + +-- ---------------------------------------------------- +-- CHANGE_MANAGEMENT_GROUPS Update all of the foreign key columns +-- ---------------------------------------------------- +update CHANGE_MANAGEMENT_SCHEDULES set change_management_group_uuid = + (select distinct s.uuid from CHANGE_MANAGEMENT_GROUPS s where change_management_groups_id = s.id); +update CHANGE_MANAGEMENT_CHANGE_WINDOWS set change_management_group_uuid = + (select distinct s.uuid from CHANGE_MANAGEMENT_GROUPS s where change_management_groups_id = s.id); + +-- ---------------------------------------------------- +-- APPROVAL_TYPES Update all of the foreign key columns +-- ---------------------------------------------------- +update SCHEDULE_APPROVALS set approval_types_uuid = + (select distinct s.uuid from APPROVAL_TYPES s where approval_type_id = s.id); + +-- ---------------------------------------------------- +-- APPROVAL_TYPES Update all of the foreign key columns +-- ---------------------------------------------------- +update SCHEDULE_APPROVALS set approval_types_uuid = + (select distinct s.uuid from SCHEDULE_APPROVALS t, APPROVAL_TYPES s where t.approval_type_id = s.id); + +SET SQL_SAFE_UPDATES = 1; diff --git a/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-drop-ids.sql b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-drop-ids.sql new file mode 100644 index 0000000..5522f64 --- /dev/null +++ b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-drop-ids.sql @@ -0,0 +1,18 @@ +USE CMSO; + +-- -------------------------------------------------------------- +-- DROP ALL OF THE INTENGER IDs +-- -------------------------------------------------------------- +ALTER TABLE SCHEDULES DROP COLUMN id; +ALTER TABLE DOMAIN_DATA DROP COLUMN id; +ALTER TABLE DOMAIN_DATA DROP COLUMN schedules_id; +ALTER TABLE APPROVAL_TYPES DROP COLUMN id; +ALTER TABLE SCHEDULE_APPROVALS DROP COLUMN id; +ALTER TABLE SCHEDULE_APPROVALS DROP COLUMN schedules_id; +ALTER TABLE SCHEDULE_APPROVALS DROP COLUMN approval_type_id; +ALTER TABLE CHANGE_MANAGEMENT_GROUPS DROP COLUMN id; +ALTER TABLE CHANGE_MANAGEMENT_GROUPS DROP COLUMN schedules_id; +ALTER TABLE CHANGE_MANAGEMENT_SCHEDULES DROP COLUMN id; +ALTER TABLE CHANGE_MANAGEMENT_SCHEDULES DROP COLUMN change_management_groups_id; +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS DROP COLUMN id; +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS DROP COLUMN change_management_groups_id; diff --git a/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-drop-indices.sql b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-drop-indices.sql new file mode 100644 index 0000000..ec74432 --- /dev/null +++ b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-drop-indices.sql @@ -0,0 +1,28 @@ +USE CMSO; + +-- ----------------------------------------------------- +-- DROP THE FOREIGN KEYS THAT USE INT IDs +-- ----------------------------------------------------- +ALTER TABLE DOMAIN_DATA DROP FOREIGN KEY FK_DOMAIN_DATA_SCHEDULES; +ALTER TABLE SCHEDULE_APPROVALS DROP FOREIGN KEY FK_SCHEDULE_APPROVALS_SCHEDULES; +ALTER TABLE CHANGE_MANAGEMENT_GROUPS DROP FOREIGN KEY FK_CHANGE_MANAGEMENT_GROUPS_SCHEDULES; +ALTER TABLE CHANGE_MANAGEMENT_SCHEDULES DROP FOREIGN KEY FK_CHANGE_MANAGEMENT_SCHEDULES_CHANGE_MANAGEMENT_GROUP; +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS DROP FOREIGN KEY FK_CHANGE_WINDOWS_CHANGE_MANAGEMENT_GROUPS1; +ALTER TABLE SCHEDULE_APPROVALS DROP FOREIGN KEY FK_SCHEDULE_APPROVALS_APPROVAL_TYPES; + +-- ----------------------------------------------------- +-- DROP THE INDEXES THAT USE INT IDs +-- ----------------------------------------------------- +DROP INDEX ID_UNIQUE ON DOMAIN_DATA; -- THIS iS NOT NECESSARY PK +DROP INDEX CHANGE_MANAGEMENT_GROUP_ID_UNIQUE ON CHANGE_MANAGEMENT_GROUPS; +DROP INDEX CHANGE_MANAGEMENT_SCHEDULES_VNF_NAME_UNIQUE ON CHANGE_MANAGEMENT_SCHEDULES; +DROP INDEX FK_DOMAIN_DATA_SCHEDULES_IDX ON DOMAIN_DATA; +DROP INDEX FK_SCHEDULE_APPROVALS_SCHEDULES_IDX ON SCHEDULE_APPROVALS; +DROP INDEX FK_APPROVAL_TYPES_IDX ON SCHEDULE_APPROVALS; +DROP INDEX FK_SCHEDULES_IDX ON CHANGE_MANAGEMENT_GROUPS; +DROP INDEX FK_CHANGE_MANAGEMENT_GROUP_CHANGE_MANAGEMENT_SCHEDULES_IDX ON CHANGE_MANAGEMENT_SCHEDULES; +DROP INDEX FK_CHANGE_WINDOWS_CHANGE_MANAGEMENT_GROUPS1_IDX on CHANGE_MANAGEMENT_CHANGE_WINDOWS; + + + + diff --git a/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-restore-indices.sql b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-restore-indices.sql new file mode 100644 index 0000000..0cb224a --- /dev/null +++ b/cmso-database/src/main/resources/cmso-dbchangelog/onap-cmso-v1.1-restore-indices.sql @@ -0,0 +1,92 @@ +USE CMSO; + +-- ----------------------------------------------------- +-- UPDATE THE PRIMARY KEYS +-- ----------------------------------------------------- +ALTER TABLE SCHEDULES DROP PRIMARY KEY, CHANGE id id INT, ADD PRIMARY KEY (uuid); +ALTER TABLE DOMAIN_DATA DROP PRIMARY KEY, CHANGE id id INT, ADD PRIMARY KEY (uuid); +ALTER TABLE APPROVAL_TYPES DROP PRIMARY KEY, CHANGE id id INT, ADD PRIMARY KEY (uuid); +ALTER TABLE SCHEDULE_APPROVALS DROP PRIMARY KEY, CHANGE id id INT, ADD PRIMARY KEY (uuid); +ALTER TABLE CHANGE_MANAGEMENT_GROUPS DROP PRIMARY KEY, CHANGE id id INT, ADD PRIMARY KEY (uuid); +ALTER TABLE CHANGE_MANAGEMENT_SCHEDULES DROP PRIMARY KEY, CHANGE id id INT, ADD PRIMARY KEY (uuid); +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS DROP PRIMARY KEY, CHANGE id id INT, ADD PRIMARY KEY (uuid); + +-- ----------------------------------------------------- +-- Table CHANGE_MANAGEMENT_DATA (DO this after we update the PK) +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS ELEMENT_DATA ( + uuid BINARY(16) NOT NULL, + change_management_schedules_uuid BINARY(16) NOT NULL, + name VARCHAR(128) NULL, + value LONGTEXT NULL, + CONSTRAINT PK_ELEMENT_DATA PRIMARY KEY (uuid), + CONSTRAINT FK_ELEMENT_DATA_CHANGE_MANAGEMENT_SCHEDULES FOREIGN KEY (change_management_schedules_uuid) + REFERENCES CHANGE_MANAGEMENT_SCHEDULES (uuid) + ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=INNODB; + +CREATE INDEX FK_ELEMENT_DATA_CHANGE_MANAGEMENT_SCHEDULES_IDX ON ELEMENT_DATA (change_management_schedules_uuid ASC); + + + + +-- ----------------------------------------------------- +-- RE_CREATE INDEXES WITH UPDATED KEYES +-- ----------------------------------------------------- +ALTER TABLE DOMAIN_DATA ADD + CONSTRAINT FK_DOMAIN_DATA_SCHEDULES FOREIGN KEY (schedules_uuid) + REFERENCES SCHEDULES (uuid) + ON DELETE NO ACTION ON UPDATE NO ACTION +; +CREATE INDEX FK_DOMAIN_DATA_SCHEDULES_IDX ON DOMAIN_DATA (schedules_uuid ASC); + + +-- ----------------------------------------------------- +ALTER TABLE SCHEDULE_APPROVALS ADD + CONSTRAINT FK_SCHEDULE_APPROVALS_SCHEDULES FOREIGN KEY (schedules_uuid) + REFERENCES SCHEDULES (uuid) + ON DELETE NO ACTION ON UPDATE NO ACTION +; +ALTER TABLE SCHEDULE_APPROVALS ADD + CONSTRAINT FK_SCHEDULE_APPROVALS_APPROVAL_TYPES FOREIGN KEY (approval_types_uuid) + REFERENCES APPROVAL_TYPES (uuid) + ON DELETE NO ACTION ON UPDATE NO ACTION +; + +CREATE INDEX FK_SCHEDULE_APPROVALS_SCHEDULES_IDX ON SCHEDULE_APPROVALS (schedules_uuid ASC); + +CREATE INDEX FK_APPROVAL_TYPES_IDX ON SCHEDULE_APPROVALS (approval_types_uuid ASC); + +-- ----------------------------------------------------- +ALTER TABLE CHANGE_MANAGEMENT_GROUPS ADD + CONSTRAINT FK_CHANGE_MANAGEMENT_GROUPS_SCHEDULES FOREIGN KEY (schedules_uuid) + REFERENCES SCHEDULES (uuid) + ON DELETE NO ACTION ON UPDATE NO ACTION +; + +CREATE INDEX FK_SCHEDULES_IDX ON CHANGE_MANAGEMENT_GROUPS (schedules_uuid ASC); + +CREATE UNIQUE INDEX CHANGE_MANAGEMENT_GROUP_ID_UNIQUE ON CHANGE_MANAGEMENT_GROUPS (schedules_uuid ASC, group_id ASC); + +-- ----------------------------------------------------- +ALTER TABLE CHANGE_MANAGEMENT_SCHEDULES ADD + CONSTRAINT FK_CHANGE_MANAGEMENT_SCHEDULES_CHANGE_MANAGEMENT_GROUP FOREIGN KEY (change_management_group_uuid) + REFERENCES CHANGE_MANAGEMENT_GROUPS (uuid) + ON DELETE NO ACTION ON UPDATE NO ACTION +; + +CREATE INDEX FK_CHANGE_MANAGEMENT_GROUP_CHANGE_MANAGEMENT_SCHEDULES_IDX ON CHANGE_MANAGEMENT_SCHEDULES (change_management_group_uuid ASC); + +CREATE UNIQUE INDEX CHANGE_MANAGEMENT_SCHEDULES_VNF_NAME_UNIQUE ON CHANGE_MANAGEMENT_SCHEDULES (change_management_group_uuid ASC, vnf_name ASC); + + +-- ----------------------------------------------------- +ALTER TABLE CHANGE_MANAGEMENT_CHANGE_WINDOWS ADD + CONSTRAINT FK_CHANGE_WINDOWS_CHANGE_MANAGEMENT_GROUPS1 FOREIGN KEY (change_management_group_uuid) + REFERENCES CHANGE_MANAGEMENT_GROUPS (uuid) + ON DELETE NO ACTION ON UPDATE NO ACTION +; + +CREATE INDEX FK_CHANGE_WINDOWS_CHANGE_MANAGEMENT_GROUPS1_IDX on CHANGE_MANAGEMENT_CHANGE_WINDOWS (change_management_group_uuid ASC); + diff --git a/cmso-database/src/main/resources/optimizer-dbchanges/onap-cmso-v1-schema.sql b/cmso-database/src/main/resources/optimizer-dbchanges/onap-cmso-v1-schema.sql new file mode 100644 index 0000000..d6e225b --- /dev/null +++ b/cmso-database/src/main/resources/optimizer-dbchanges/onap-cmso-v1-schema.sql @@ -0,0 +1,51 @@ +CREATE SCHEMA IF NOT EXISTS `optimizer` DEFAULT CHARACTER SET utf8 ; + +CREATE TABLE IF NOT EXISTS `optimizer`.`request` ( + uuid BINARY(16) NOT NULL, + request LONGTEXT NOT NULL, + created_time BIGINT(20) NULL DEFAULT NULL, + request_start BIGINT(20) NULL DEFAULT NULL, + request_end BIGINT(20) NULL DEFAULT NULL, + status VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY (`uuid`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + +CREATE TABLE IF NOT EXISTS `optimizer`.`response` ( + uuid BINARY(16) NOT NULL, + repsonse LONGTEXT NULL DEFAULT NULL, + delivered_time BIGINT(20) NULL DEFAULT NULL, + PRIMARY KEY (`uuid`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +CREATE TABLE IF NOT EXISTS `optimizer`.`topology` ( + uuid BINARY(16) NOT NULL, + topology LONGTEXT NULL DEFAULT NULL, + topology_start BIGINT(20) NULL DEFAULT NULL, + topology_end BIGINT(20) NULL DEFAULT NULL, + topology_retries INT NULL DEFAULT NULL, + PRIMARY KEY (`uuid`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + +CREATE TABLE IF NOT EXISTS `optimizer`.`tickets` ( + uuid BINARY(16) NOT NULL, + tickets LONGTEXT NULL DEFAULT NULL, + tickets_start BIGINT(20) NULL DEFAULT NULL, + tickets_end BIGINT(20) NULL DEFAULT NULL, + tickets_retries INT NULL DEFAULT NULL, + PRIMARY KEY (`uuid`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + +CREATE TABLE IF NOT EXISTS `optimizer`.`optimizer` ( + uuid BINARY(16) NOT NULL, + optimize_response LONGTEXT NULL DEFAULT NULL, + optimize_start BIGINT(20) NULL DEFAULT NULL, + optimize_end BIGINT(20) NULL DEFAULT NULL, + optimize_retries INT NULL DEFAULT NULL, + PRIMARY KEY (`uuid`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; diff --git a/cmso-robot/robot/assets/sql/selectall.sql b/cmso-robot/robot/assets/sql/selectall.sql index ba41595..4ffae93 100644 --- a/cmso-robot/robot/assets/sql/selectall.sql +++ b/cmso-robot/robot/assets/sql/selectall.sql @@ -1,9 +1,10 @@ -select * from DOMAINS; -select * from DOMAIN_DATA order by schedules_id desc; -select * from CHANGE_MANAGEMENT_SCHEDULES order by id desc; -select * from CHANGE_MANAGEMENT_CHANGE_WINDOWS; -select * from CHANGE_MANAGEMENT_GROUPS; -select * from SCHEDULES order by id desc; -select * from APPROVAL_TYPES; -select * from SCHEDULE_APPROVALS; -select * from SCHEDULE_EVENTS;
\ No newline at end of file +select DOMAINS.* from CMSO.DOMAINS; +select hex(uuid), hex(schedules_uuid), DOMAIN_DATA.* from CMSO.DOMAIN_DATA order by schedules_uuid; +select hex(uuid), hex(change_management_group_uuid), CHANGE_MANAGEMENT_SCHEDULES.* from CMSO.CHANGE_MANAGEMENT_SCHEDULES order by uuid desc; +select hex(uuid), hex(schedules_uuid), hex(change_management_group_uuid), CHANGE_MANAGEMENT_CHANGE_WINDOWS.* from CMSO.CHANGE_MANAGEMENT_CHANGE_WINDOWS; +select hex(uuid), hex(schedules_uuid), CHANGE_MANAGEMENT_GROUPS.* from CMSO.CHANGE_MANAGEMENT_GROUPS; +select hex(uuid), SCHEDULES.* from CMSO.SCHEDULES order by create_date_time desc; +select hex(uuid), APPROVAL_TYPES.* from CMSO.APPROVAL_TYPES; +select hex(uuid), hex(approval_types_uuid), hex(schedules_uuid), SCHEDULE_APPROVALS.* from CMSO.SCHEDULE_APPROVALS; +select hex(uuid), hex(change_management_schedules_uuid), ELEMENT_DATA.* from CMSO.ELEMENT_DATA; + 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/pom.xml b/cmso-service/pom.xml index a68744b..d64709e 100644 --- a/cmso-service/pom.xml +++ b/cmso-service/pom.xml @@ -56,7 +56,7 @@ <pact.version>3.3.9</pact.version>
<spring.version>5.0.10.RELEASE</spring.version>
<spring.boot.version>2.1.3.RELEASE</spring.boot.version>
- <springfox.swagger2.version>2.9.2</springfox.swagger2.version>
+ <swagger.core.version>2.0.0</swagger.core.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
@@ -65,7 +65,7 @@ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
<mariadb.version>2.2.1</mariadb.version>
- <swagger.directory>${basedir}/src/main/resources/swagger-ui/dist</swagger.directory>
+ <swagger.directory>${basedir}/src/main/resources/META-INF/resources/swagger/</swagger.directory>
<aaf.version>2.1.4</aaf.version>
<!-- Sonar -->
@@ -230,15 +230,23 @@ <!--Swagger Dependencies -->
<dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>${springfox.swagger2.version}</version>
+ <groupId>io.swagger.core.v3</groupId>
+ <artifactId>swagger-jaxrs2</artifactId>
+ <version>${swagger.core.version}</version>
</dependency>
<dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>${springfox.swagger2.version}</version>
+ <groupId>io.swagger.core.v3</groupId>
+ <artifactId>swagger-jaxrs2-servlet-initializer</artifactId>
+ <version>${swagger.core.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jersey2-jaxrs</artifactId>
+ <version>1.5.0</version>
+ </dependency>
+
+
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java b/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java index 9b10d51..9189326 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java @@ -42,7 +42,7 @@ import org.glassfish.jersey.servlet.ServletProperties; import org.onap.optf.cmso.dispatcher.rs.DispatcherServiceImpl;
import org.onap.optf.cmso.filters.CMSOContainerFilters;
import org.onap.optf.cmso.service.rs.AdminToolImpl;
-import org.onap.optf.cmso.service.rs.CMSCallbackImpl;
+import org.onap.optf.cmso.service.rs.CMSOOptimizerCallbackImpl;
import org.onap.optf.cmso.service.rs.CMSOServiceImpl;
import org.onap.optf.cmso.service.rs.HealthCheckImpl;
import org.onap.optf.cmso.test.loopback.SchedulerTestLoopbackServiceImpl;
@@ -76,7 +76,7 @@ public class JerseyConfiguration extends ResourceConfig { @Autowired
public JerseyConfiguration( /* LogRequestFilter lrf */ ) {
register(CMSOServiceImpl.class);
- register(CMSCallbackImpl.class);
+ register(CMSOOptimizerCallbackImpl.class);
register(SchedulerTestLoopbackServiceImpl.class);
register(TicketMgtLoopbackServiceImpl.class);
register(HealthCheckImpl.class);
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispacherService.java b/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispacherService.java index d0ff299..adc3260 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispacherService.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispacherService.java @@ -1,6 +1,6 @@ /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * 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.
@@ -40,6 +40,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispatcherServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispatcherServiceImpl.java index 3aab301..67a69cb 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispatcherServiceImpl.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/dispatcher/rs/DispatcherServiceImpl.java @@ -58,7 +58,7 @@ public class DispatcherServiceImpl implements DispacherService { DispatchJob dispatchJob;
@Autowired
- CMSOptimizerClient sniroClient;
+ CMSOptimizerClient optimizerClient;
@Autowired
TmStatusClient tmStatusClient;
@@ -85,7 +85,7 @@ public class DispatcherServiceImpl implements DispacherService { public Response dispatchOptimizer(Integer id, UriInfo uri, HttpServletRequest request) {
debug.debug("dispatchOptimizer entered {}", id);
try {
- sniroClient.scheduleSniroOptimization(id);
+ optimizerClient.scheduleOptimization(id);
} catch (Exception e) {
errors.error(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());
debug.error(e.getMessage(), e);
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java index 5d500d2..9feea2d 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java @@ -85,15 +85,15 @@ public class CMSOptimizerClient { @Autowired
PropertiesManagement pm;
- public boolean scheduleSniroOptimization(Integer id) {
+ public boolean scheduleOptimization(Integer id) {
Map<String, String> mdcSave = Mdc.save();
try {
- String snirourl = env.getProperty("cmso.optimizer.url");
- String snirocallbackurl = env.getProperty("cmso.optimizer.callbackurl");
+ String optimizerurl = env.getProperty("cmso.optimizer.url");
+ String optimizercallbackurl = env.getProperty("cmso.optimizer.callbackurl");
String username = env.getProperty("mechid.user");
- Integer maxAttempts = env.getProperty("cmso.sniro.maxAttempts", Integer.class, 20);
+ Integer maxAttempts = env.getProperty("cmso.optimizer.maxAttempts", Integer.class, 20);
- // Ensure that only one cmso is requsting this call to SNIRO
+ // Ensure that only one cmso is requsting this call to optimizer
Schedule schedule = scheduleDAO.lockOne(id);
if (!schedule.getStatus().equals(CMSStatusEnum.PendingSchedule.toString()))
return false;
@@ -116,7 +116,7 @@ public class CMSOptimizerClient { if (info == null) {
return true;
}
- buildRequest(cmReq, info, schedule, snirocallbackurl);
+ buildRequest(cmReq, info, schedule, optimizercallbackurl);
} catch (Exception e) {
Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
@@ -126,34 +126,34 @@ public class CMSOptimizerClient { }
// This service will call SNIO for each PendingOptimiztion
- // If the request is successfully scheduled in SNIRO, status will be
+ // If the request is successfully scheduled in optimizer, status will be
// updated to OptimizationInProgress.
Client client = ClientBuilder.newClient();
client.register(new BasicAuthenticatorFilter(username, password));
client.register(new CMSOClientFilters());
- WebTarget sniroTarget = client.target(snirourl);
- Invocation.Builder invocationBuilder = sniroTarget.request(MediaType.APPLICATION_JSON);
+ WebTarget optimizerTarget = client.target(optimizerurl);
+ Invocation.Builder invocationBuilder = optimizerTarget.request(MediaType.APPLICATION_JSON);
try {
//
// First, push OptimizationInProgress to the DB (flush()) assuming a 202 status,
- // in case the SNIRO callback is received prior to the
+ // in case the optimizer callback is received prior to the
// commit of this transaction.
- // SNIRO Callback will throw an error if it receives a response in the incorrect
+ // optimizer Callback will throw an error if it receives a response in the incorrect
// state.
//
schedule.setOptimizerTransactionId(cmReq.getRequestInfo().getTransactionId());
schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
schedule.setStatus(CMSStatusEnum.OptimizationInProgress.toString());
updateScheduleStatus(schedule);
- debug.debug("SNIRO url / user: " + snirourl + " / " + username);
- debug.debug("SNIRO Request: " + new ObjectMapper().writeValueAsString(cmReq));
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", schedule.getScheduleId(), snirourl);
+ debug.debug("optimizer url / user: " + optimizerurl + " / " + username);
+ debug.debug("optimizer Request: " + new ObjectMapper().writeValueAsString(cmReq));
+ Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", schedule.getScheduleId(), optimizerurl);
Response response = invocationBuilder.post(Entity.json(cmReq));
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", schedule.getScheduleId(), snirourl);
+ Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", schedule.getScheduleId(), optimizerurl);
switch (response.getStatus()) {
case 202:
debug.debug("Successfully scheduled optimization: " + schedule.getScheduleId());
- // Scheduled with SNIRO
+ // Scheduled with optimizer
break;
case 400: // Bad request
{
@@ -162,7 +162,7 @@ public class CMSOptimizerClient { String message = response.readEntity(String.class);
schedule.setOptimizerMessage(message);
schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());
- // Need to understand the cause of this error. May be teh same as SNIRO
+ // Need to understand the cause of this error. May be teh same as optimizer
// down.
int tries = schedule.getOptimizerAttemptsToSchedule();
tries++;
@@ -195,24 +195,24 @@ public class CMSOptimizerClient { return true;
} catch (ResponseProcessingException e) {
schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
- schedule.setOptimizerStatus("Failed to parse SNIRO response");
+ schedule.setOptimizerStatus("Failed to parse optimizer response");
schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());
- // Need to understand the cause of this error. May be teh same as SNIRO down.
+ // Need to understand the cause of this error. May be teh same as optimizer down.
int tries = schedule.getOptimizerAttemptsToSchedule();
tries++;
schedule.setOptimizerAttemptsToSchedule(tries);
updateScheduleStatus(schedule);
- // Getting invalid response from SNIRO.
+ // Getting invalid response from optimizer.
// May be data related.
Observation.report(LogMessages.OPTIMIZER_EXCEPTION, e, e.getMessage());
return false;
} catch (ProcessingException e) {
- // Don't track number of retries on IO error (SNIRO is down)
+ // Don't track number of retries on IO error (optimizer is down)
schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
schedule.setStatus(CMSStatusEnum.PendingSchedule.toString());
updateScheduleStatus(schedule);
- /// Cannot connect to SNIRO
+ /// Cannot connect to optimizer
Observation.report(LogMessages.OPTIMIZER_EXCEPTION, e, e.getMessage());
// Wait until next cycle
return false;
@@ -226,15 +226,15 @@ public class CMSOptimizerClient { return false;
}
- private void buildRequest(CMOptimizerRequest cmReq, CMSInfo info, Schedule schedule, String snirocallbackurl) {
+ private void buildRequest(CMOptimizerRequest cmReq, CMSInfo info, Schedule schedule, String optimizercallbackurl) {
- // TODO: Need to get SNIRO to accept ChangeManagementSchedulingInfo
- // This is to support 1707 SNIRO interface
+ // TODO: Need to get optimizer to accept ChangeManagementSchedulingInfo
+ // This is to support 1707 optimizer interface
CMRequestInfo reqInfo = cmReq.getRequestInfo();
CMSchedulingInfo schInfo = cmReq.getSchedulingInfo();
UUID uuid = UUID.randomUUID();
- reqInfo.setCallbackUrl(snirocallbackurl);
+ reqInfo.setCallbackUrl(optimizercallbackurl);
reqInfo.setOptimizer(new String[] {"scheduling"});
reqInfo.setTransactionId(schedule.getOptimizerTransactionId());
reqInfo.setRequestId("CM-" + uuid.toString());
@@ -283,7 +283,7 @@ public class CMSOptimizerClient { // Perhaps We create ChangeManagementSchedulingInfoV1, ...V2, etc.
// ANd try them one after another....
Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, "Unable to parse message. Format changed?");
- schedule.setOptimizerStatus("Failed to parse SNIRO request");
+ schedule.setOptimizerStatus("Failed to parse optimizer request");
schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
scheduleDAO.save(schedule);
@@ -300,12 +300,12 @@ public class CMSOptimizerClient { public HealthCheckComponent healthCheck() {
Map<String, String> mdcSave = Mdc.save();
HealthCheckComponent hcc = new HealthCheckComponent();
- hcc.setName("SNIRO Interface");
- String snirourl = env.getProperty("cmso.optimizer.url");
- String snirocallbackurl = env.getProperty("cmso.optimizer.callbackurl");
+ hcc.setName("OPtimizer Interface");
+ String optimizerurl = env.getProperty("cmso.optimizer.url");
+ String optimizercallbackurl = env.getProperty("cmso.optimizer.callbackurl");
String username = env.getProperty("mechid.user");
String password = pm.getProperty("mechid.pass", "");
- hcc.setUrl(snirourl);
+ hcc.setUrl(optimizerurl);
try {
UUID uuid = UUID.randomUUID();
// Build a bogus request should fail policy validation
@@ -335,22 +335,22 @@ public class CMSOptimizerClient { client.register(new BasicAuthenticatorFilter(username, password));
client.register(new CMSOClientFilters());
- WebTarget sniroTarget = client.target(snirourl);
- Invocation.Builder invocationBuilder = sniroTarget.request(MediaType.APPLICATION_JSON);
- debug.debug("SNIRO url / user: " + snirourl + " / " + username);
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", "healthcheck", snirourl);
+ WebTarget optimizerTarget = client.target(optimizerurl);
+ Invocation.Builder invocationBuilder = optimizerTarget.request(MediaType.APPLICATION_JSON);
+ debug.debug("Optimizer url / user: " + optimizerurl + " / " + username);
+ Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", "healthcheck", optimizerurl);
Response response = invocationBuilder.post(Entity.json(cmReq));
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", "healthcheck", snirourl);
+ Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", "healthcheck", optimizerurl);
String message = response.getStatus() + ":" + response.readEntity(String.class);
switch (response.getStatus()) {
case 202:
- debug.debug("Successful SNIRO healthcheck");
+ debug.debug("Successful optimizer healthcheck");
hcc.setHealthy(true);
break;
case 400:
// Expecting policy not found.
if (message.contains("Cannot fetch policy")) {
- debug.debug("Successful SNIRO healthcheck");
+ debug.debug("Successful optimizer healthcheck");
hcc.setHealthy(true);
hcc.setStatus("OK");
} else {
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/bean/CMOptimizerResponse.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/bean/CMOptimizerResponse.java index a50025b..6dd7bdf 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/bean/CMOptimizerResponse.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/bean/CMOptimizerResponse.java @@ -1,6 +1,6 @@ /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * 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.
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java index 801986c..10eedf8 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java @@ -1,6 +1,6 @@ /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * 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.
@@ -31,23 +31,21 @@ package org.onap.optf.cmso.service.rs;
-import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-@Api
+@Api("CMSO Administration")
@Path("/{apiVersion}")
@Produces({MediaType.APPLICATION_JSON})
public interface AdminTool {
@@ -60,7 +58,6 @@ public interface AdminTool { @ApiResponses(
value = {@ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Request failed")})
public Response exec(@ApiParam(value = "v1|v2") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
- @ApiParam(value = "Identifier", allowMultiple = true) @PathParam("id") String id, @Context UriInfo uri,
- @Context HttpServletRequest request);
+ @ApiParam(value = "Identifier", allowMultiple = true) @PathParam("id") String id);
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java index b878d31..8ec4f4f 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java @@ -31,32 +31,38 @@ package org.onap.optf.cmso.service.rs;
-import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-import org.onap.observations.Mdc;
import org.onap.optf.cmso.common.PropertiesManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@Controller
public class AdminToolImpl implements AdminTool {
private static EELFLogger log = EELFManager.getInstance().getLogger(AdminToolImpl.class);
- private static EELFLogger audit = EELFManager.getInstance().getAuditLogger();
+
+ @Context
+ UriInfo uri;
+
+ @Context
+ HttpServletRequest request;
+
@Autowired
PropertiesManagement pm;
@Override
- public Response exec(String apiVersion, String id, UriInfo uri, HttpServletRequest request) {
+ public Response exec(String apiVersion, String id) {
log.info("AdminTool.exec entered");
if (id.length() < 4)
return Response.ok("").build();
- String encrypted = pm.getEncryptedValue(id);
+ String encrypted = PropertiesManagement.getEncryptedValue(id);
Response response = Response.ok(encrypted).build();
return response;
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSCallbackImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOOptimizerCallbackImpl.java index 5d11225..679dd02 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSCallbackImpl.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOOptimizerCallbackImpl.java @@ -1,260 +1,269 @@ -/*
- * 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;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.transaction.Transactional;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.UriInfo;
-import org.joda.time.DateTime;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.ISODateTimeFormat;
-import org.onap.observations.Mdc;
-import org.onap.optf.cmso.common.CMSStatusEnum;
-import org.onap.optf.cmso.common.DomainsEnum;
-import org.onap.optf.cmso.common.LogMessages;
-import org.onap.optf.cmso.common.exceptions.CMSException;
-import org.onap.optf.cmso.common.exceptions.CMSNotFoundException;
-import org.onap.optf.cmso.model.ChangeManagementGroup;
-import org.onap.optf.cmso.model.ChangeManagementSchedule;
-import org.onap.optf.cmso.model.Schedule;
-import org.onap.optf.cmso.model.dao.ChangeManagementChangeWindowDAO;
-import org.onap.optf.cmso.model.dao.ChangeManagementDetailDAO;
-import org.onap.optf.cmso.model.dao.ChangeManagementGroupDAO;
-import org.onap.optf.cmso.model.dao.ChangeManagementScheduleDAO;
-import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse;
-import org.onap.optf.cmso.optimizer.bean.CMSchedule;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-@Controller
-public class CMSCallbackImpl extends BaseSchedulerServiceImpl implements CMSOptimizerCallback {
- private static EELFLogger log = EELFManager.getInstance().getLogger(CMSCallbackImpl.class);
- private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger();
- private static EELFLogger audit = EELFManager.getInstance().getAuditLogger();
- private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
- private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
-
- @Autowired
- ChangeManagementScheduleDAO cmScheduleDAO;
-
- @Autowired
- ChangeManagementGroupDAO cmGroupDAO;
-
- @Autowired
- ChangeManagementChangeWindowDAO cmChangeWindowDAO;
-
- @Autowired
- ChangeManagementDetailDAO cmDetailsDAO;
-
- @Override
- @Transactional
- public Response sniroCallback(String apiVersion, CMOptimizerResponse sniroResponse, UriInfo uri,
- HttpServletRequest request) {
- Response response = null;
- log.info(LogMessages.PROCESS_OPTIMIZER_CALLBACK, "Received", request.getRemoteAddr(), "");
- log.info(LogMessages.OPTIMIZER_REQUEST, "Callback received", sniroResponse.getTransactionId(),
- uri.getAbsolutePath().toString());
- try {
- // Note that transaction ID and schedule ID are currently the same value.
-
- String transactionId = sniroResponse.getTransactionId();
-
- // Synchronize this with transaction that scheduled the SNIRO optimization
- // to ensure status updates are properly ordered.
- // This is necessary only in the race condition where SNIRO callback comes
- // before the SNIRO response is processed and the scheduling transaction is
- // still in flight.
- // Note that this may happen in loopback mode, but is not likely to happen with
- // real SNIRO unless SNIRO changes to be synchronous and the callback comes before
- // the response.
- // If this lock times out, the schedule will remain in 'Optimization In
- // Progress' and never complete.
- Schedule schedule = scheduleDAO.lockOneByTransactionId(transactionId);
-
- if (schedule == null) {
- throw new CMSNotFoundException(DomainsEnum.ChangeManagement.toString(),
- "(OptimizerTransactionID=" + transactionId + ")");
-
- }
- CMSStatusEnum status = CMSStatusEnum.PendingApproval.fromString(schedule.getStatus());
- debug.debug("Status at time of SNIRO callback is " + status.toString());
- switch (status) {
- // PendingSchedule may be a valid status in the cases where SNIRO async call
- // returns before
- // We have committed the OptimizationInProgress status
- // The dispatch logic ensures that we only every dispatch once.
- case OptimizationInProgress:
- processSniroResponse(sniroResponse, schedule);
- scheduleDAO.save(schedule);
- response = Response.ok().build();
- break;
- default:
- throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.OPTIMIZER_CALLBACK_STATE_ERROR,
- CMSStatusEnum.OptimizationInProgress.toString(), schedule.getStatus().toString());
- }
- } catch (CMSException e) {
- errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
- } catch (Exception e) {
- errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.serverError().entity(e.getMessage()).build();
- } finally {
- }
- return response;
- }
-
- private void processSniroResponse(CMOptimizerResponse sniroResponse, Schedule schedule) {
- try {
- schedule.setOptimizerReturnDateTimeMillis(System.currentTimeMillis());
- schedule.setOptimizerStatus(sniroResponse.getRequestState());
- schedule.setOptimizerMessage(sniroResponse.getDescription());
- String scheduleId = sniroResponse.getScheduleId();
- ObjectMapper om = new ObjectMapper();
- CMSchedule[] scheduleArray = sniroResponse.getSchedule();
- if (scheduleArray != null && scheduleArray.length > 0) {
- String scheduleString = om.writeValueAsString(scheduleArray);
- schedule.setSchedule(scheduleString);
- log.debug("scheduleId={0} schedule={1}", scheduleId, scheduleString);
- for (CMSchedule sniroSchedule : sniroResponse.getSchedule()) {
- String groupId = sniroSchedule.getGroupId();
- DateTime finishTime = convertDate(sniroSchedule.getFinishTime(), "finishTime");
- DateTime latestInstanceStartTime =
- convertDate(sniroSchedule.getLatestInstanceStartTime(), "latestInstanceStartTime");
- DateTime startTime = convertDate(sniroSchedule.getStartTime(), "startTime");
- ChangeManagementGroup group = cmGroupDAO.findOneBySchedulesIDGroupID(schedule.getId(), groupId);
- if (group == null) {
- throw new CMSException(Status.PRECONDITION_FAILED,
- LogMessages.CHANGE_MANAGEMENT_GROUP_NOT_FOUND, schedule.getScheduleId(), groupId);
- }
- group.setStartTimeMillis(startTime.getMillis());
- group.setFinishTimeMillis(finishTime.getMillis());
- group.setLastInstanceStartTimeMillis(latestInstanceStartTime.getMillis());
- cmGroupDAO.save(group);
- long totalDuration =
- (group.getAdditionalDurationInSecs() + group.getNormalDurationInSecs()) * 1000l;
- Map<String, Map<String, Long>> startAndFinishTimeMap = new HashMap<String, Map<String, Long>>();
- makeMap(startTime.getMillis(), latestInstanceStartTime.getMillis(), group.getConcurrencyLimit(),
- totalDuration, sniroSchedule.getNode(), startAndFinishTimeMap);
- for (String node : sniroSchedule.getNode()) {
- processNode(schedule, group, node, startAndFinishTimeMap);
- }
- }
- schedule.setStatus(CMSStatusEnum.PendingApproval.toString());
- } else {
- debug.debug("scheduleId={0} schedule=null status={1} ", scheduleId, schedule.getOptimizerStatus());
- schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
- }
- } catch (CMSException e) {
- errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
- schedule.setOptimizerStatus(e.getStatus().toString());
- schedule.setOptimizerMessage(e.getLocalizedMessage());
- } catch (Exception e) {
- errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
- schedule.setOptimizerStatus("Exception");
- schedule.setOptimizerMessage(e.getLocalizedMessage());
- }
- }
-
- public static void makeMap(Long startTime, Long latestInstanceStartTime, int concurrencyLimit, long totalDuration,
- List<String> nodes, Map<String, Map<String, Long>> startAndFinishTimeMap) throws CMSException {
- Long nextStartTime = null;
- Long nextFinishTime = null;
- for (int nodeNumber = 0; nodeNumber < nodes.size(); nodeNumber++) {
- String node = nodes.get(nodeNumber);
- if (nodeNumber % concurrencyLimit == 0) {
- if (nodeNumber == 0)
- nextStartTime = startTime;
- else
- nextStartTime = nextStartTime + totalDuration;
- if (nextStartTime > latestInstanceStartTime) {
- throw new CMSException(Status.BAD_REQUEST, LogMessages.UNABLE_TO_ALLOCATE_VNF_TIMESLOTS,
- startTime.toString(), latestInstanceStartTime.toString(), String.valueOf(totalDuration),
- String.valueOf(concurrencyLimit), String.valueOf(nodes.size()));
- }
- nextFinishTime = nextStartTime + totalDuration;
- }
- Map<String, Long> map = new HashMap<String, Long>();
- map.put("startTime", nextStartTime);
- map.put("finishTime", nextFinishTime);
- startAndFinishTimeMap.put(node, map);
- }
-
- }
-
- private void processNode(Schedule schedule, ChangeManagementGroup group, String node,
- Map<String, Map<String, Long>> startAndFinishTimeMap) throws CMSException {
- Map<String, Long> map = startAndFinishTimeMap.get(node);
- ChangeManagementSchedule detail = cmScheduleDAO.findOneByGroupIDAndVnfName(group.getId(), node);
- if (detail == null) {
- throw new CMSException(Status.NOT_FOUND, LogMessages.UNABLE_TO_LOCATE_SCHEDULE_DETAIL,
- schedule.getScheduleId(), group.getGroupId(), node);
- }
- detail.setStartTimeMillis(map.get("startTime"));
- detail.setFinishTimeMillis(map.get("finishTime"));
- detail.setVnfId("");
- detail.setStatus(CMSStatusEnum.PendingApproval.toString());
- cmScheduleDAO.save(detail);
- }
-
- public static DateTime convertDate(String utcDate, String attrName) throws CMSException {
- try {
- DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZoneUTC().parseDateTime(utcDate);
- if (dateTime != null)
- return dateTime;
- } catch (Exception e) {
- debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- }
- throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, attrName, utcDate);
- }
-
- public static DateTime convertISODate(String utcDate, String attrName) throws CMSException {
- try {
- DateTime dateTime = ISODateTimeFormat.dateTimeParser().parseDateTime(utcDate);
- if (dateTime != null)
- return dateTime;
- } catch (Exception e) {
- debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- }
- throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, attrName, utcDate);
- }
-
-}
+/* + * 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; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.transaction.Transactional; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; + +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.ISODateTimeFormat; +import org.onap.optf.cmso.common.CMSStatusEnum; +import org.onap.optf.cmso.common.DomainsEnum; +import org.onap.optf.cmso.common.LogMessages; +import org.onap.optf.cmso.common.exceptions.CMSException; +import org.onap.optf.cmso.common.exceptions.CMSNotFoundException; +import org.onap.optf.cmso.model.ChangeManagementGroup; +import org.onap.optf.cmso.model.ChangeManagementSchedule; +import org.onap.optf.cmso.model.Schedule; +import org.onap.optf.cmso.model.dao.ChangeManagementChangeWindowDAO; +import org.onap.optf.cmso.model.dao.ChangeManagementDetailDAO; +import org.onap.optf.cmso.model.dao.ChangeManagementGroupDAO; +import org.onap.optf.cmso.model.dao.ChangeManagementScheduleDAO; +import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse; +import org.onap.optf.cmso.optimizer.bean.CMSchedule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class CMSOOptimizerCallbackImpl extends BaseSchedulerServiceImpl implements CMSOptimizerCallback { + private static EELFLogger log = EELFManager.getInstance().getLogger(CMSOOptimizerCallbackImpl.class); + private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger(); + private static EELFLogger audit = EELFManager.getInstance().getAuditLogger(); + private static EELFLogger debug = EELFManager.getInstance().getDebugLogger(); + private static EELFLogger errors = EELFManager.getInstance().getErrorLogger(); + + @Context + UriInfo uri; + + @Context + HttpServletRequest request; + + + @Autowired + ChangeManagementScheduleDAO cmScheduleDAO; + + @Autowired + ChangeManagementGroupDAO cmGroupDAO; + + @Autowired + ChangeManagementChangeWindowDAO cmChangeWindowDAO; + + @Autowired + ChangeManagementDetailDAO cmDetailsDAO; + + @Override + @Transactional + public Response sniroCallback(String apiVersion, CMOptimizerResponse sniroResponse) { + Response response = null; + log.info(LogMessages.PROCESS_OPTIMIZER_CALLBACK, "Received", request.getRemoteAddr(), ""); + log.info(LogMessages.OPTIMIZER_REQUEST, "Callback received", sniroResponse.getTransactionId(), + uri.getAbsolutePath().toString()); + try { + // Note that transaction ID and schedule ID are currently the same value. + + String transactionId = sniroResponse.getTransactionId(); + + // Synchronize this with transaction that scheduled the SNIRO optimization + // to ensure status updates are properly ordered. + // This is necessary only in the race condition where SNIRO callback comes + // before the SNIRO response is processed and the scheduling transaction is + // still in flight. + // Note that this may happen in loopback mode, but is not likely to happen with + // real SNIRO unless SNIRO changes to be synchronous and the callback comes before + // the response. + // If this lock times out, the schedule will remain in 'Optimization In + // Progress' and never complete. + Schedule schedule = scheduleDAO.lockOneByTransactionId(transactionId); + + if (schedule == null) { + throw new CMSNotFoundException(DomainsEnum.ChangeManagement.toString(), + "(OptimizerTransactionID=" + transactionId + ")"); + + } + CMSStatusEnum status = CMSStatusEnum.PendingApproval.fromString(schedule.getStatus()); + debug.debug("Status at time of SNIRO callback is " + status.toString()); + switch (status) { + // PendingSchedule may be a valid status in the cases where SNIRO async call + // returns before + // We have committed the OptimizationInProgress status + // The dispatch logic ensures that we only every dispatch once. + case OptimizationInProgress: + processSniroResponse(sniroResponse, schedule); + scheduleDAO.save(schedule); + response = Response.ok().build(); + break; + default: + throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.OPTIMIZER_CALLBACK_STATE_ERROR, + CMSStatusEnum.OptimizationInProgress.toString(), schedule.getStatus().toString()); + } + } catch (CMSException e) { + errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + response = Response.status(e.getStatus()).entity(e.getRequestError()).build(); + } catch (Exception e) { + errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + response = Response.serverError().entity(e.getMessage()).build(); + } finally { + } + return response; + } + + private void processSniroResponse(CMOptimizerResponse sniroResponse, Schedule schedule) { + try { + schedule.setOptimizerReturnDateTimeMillis(System.currentTimeMillis()); + schedule.setOptimizerStatus(sniroResponse.getRequestState()); + schedule.setOptimizerMessage(sniroResponse.getDescription()); + String scheduleId = sniroResponse.getScheduleId(); + ObjectMapper om = new ObjectMapper(); + CMSchedule[] scheduleArray = sniroResponse.getSchedule(); + if (scheduleArray != null && scheduleArray.length > 0) { + String scheduleString = om.writeValueAsString(scheduleArray); + schedule.setSchedule(scheduleString); + log.debug("scheduleId={0} schedule={1}", scheduleId, scheduleString); + for (CMSchedule sniroSchedule : sniroResponse.getSchedule()) { + String groupId = sniroSchedule.getGroupId(); + DateTime finishTime = convertDate(sniroSchedule.getFinishTime(), "finishTime"); + DateTime latestInstanceStartTime = + convertDate(sniroSchedule.getLatestInstanceStartTime(), "latestInstanceStartTime"); + DateTime startTime = convertDate(sniroSchedule.getStartTime(), "startTime"); + ChangeManagementGroup group = cmGroupDAO.findOneBySchedulesIDGroupID(schedule.getId(), groupId); + if (group == null) { + throw new CMSException(Status.PRECONDITION_FAILED, + LogMessages.CHANGE_MANAGEMENT_GROUP_NOT_FOUND, schedule.getScheduleId(), groupId); + } + group.setStartTimeMillis(startTime.getMillis()); + group.setFinishTimeMillis(finishTime.getMillis()); + group.setLastInstanceStartTimeMillis(latestInstanceStartTime.getMillis()); + cmGroupDAO.save(group); + long totalDuration = + (group.getAdditionalDurationInSecs() + group.getNormalDurationInSecs()) * 1000l; + Map<String, Map<String, Long>> startAndFinishTimeMap = new HashMap<String, Map<String, Long>>(); + makeMap(startTime.getMillis(), latestInstanceStartTime.getMillis(), group.getConcurrencyLimit(), + totalDuration, sniroSchedule.getNode(), startAndFinishTimeMap); + for (String node : sniroSchedule.getNode()) { + processNode(schedule, group, node, startAndFinishTimeMap); + } + } + schedule.setStatus(CMSStatusEnum.PendingApproval.toString()); + } else { + debug.debug("scheduleId={0} schedule=null status={1} ", scheduleId, schedule.getOptimizerStatus()); + schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString()); + } + } catch (CMSException e) { + errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString()); + schedule.setOptimizerStatus(e.getStatus().toString()); + schedule.setOptimizerMessage(e.getLocalizedMessage()); + } catch (Exception e) { + errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString()); + schedule.setOptimizerStatus("Exception"); + schedule.setOptimizerMessage(e.getLocalizedMessage()); + } + } + + public static void makeMap(Long startTime, Long latestInstanceStartTime, int concurrencyLimit, long totalDuration, + List<String> nodes, Map<String, Map<String, Long>> startAndFinishTimeMap) throws CMSException { + Long nextStartTime = null; + Long nextFinishTime = null; + for (int nodeNumber = 0; nodeNumber < nodes.size(); nodeNumber++) { + String node = nodes.get(nodeNumber); + if (nodeNumber % concurrencyLimit == 0) { + if (nodeNumber == 0) + nextStartTime = startTime; + else + nextStartTime = nextStartTime + totalDuration; + if (nextStartTime > latestInstanceStartTime) { + throw new CMSException(Status.BAD_REQUEST, LogMessages.UNABLE_TO_ALLOCATE_VNF_TIMESLOTS, + startTime.toString(), latestInstanceStartTime.toString(), String.valueOf(totalDuration), + String.valueOf(concurrencyLimit), String.valueOf(nodes.size())); + } + nextFinishTime = nextStartTime + totalDuration; + } + Map<String, Long> map = new HashMap<String, Long>(); + map.put("startTime", nextStartTime); + map.put("finishTime", nextFinishTime); + startAndFinishTimeMap.put(node, map); + } + + } + + private void processNode(Schedule schedule, ChangeManagementGroup group, String node, + Map<String, Map<String, Long>> startAndFinishTimeMap) throws CMSException { + Map<String, Long> map = startAndFinishTimeMap.get(node); + ChangeManagementSchedule detail = cmScheduleDAO.findOneByGroupIDAndVnfName(group.getId(), node); + if (detail == null) { + throw new CMSException(Status.NOT_FOUND, LogMessages.UNABLE_TO_LOCATE_SCHEDULE_DETAIL, + schedule.getScheduleId(), group.getGroupId(), node); + } + detail.setStartTimeMillis(map.get("startTime")); + detail.setFinishTimeMillis(map.get("finishTime")); + detail.setVnfId(""); + detail.setStatus(CMSStatusEnum.PendingApproval.toString()); + cmScheduleDAO.save(detail); + } + + public static DateTime convertDate(String utcDate, String attrName) throws CMSException { + try { + DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZoneUTC().parseDateTime(utcDate); + if (dateTime != null) + return dateTime; + } catch (Exception e) { + debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + } + throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, attrName, utcDate); + } + + public static DateTime convertISODate(String utcDate, String attrName) throws CMSException { + try { + DateTime dateTime = ISODateTimeFormat.dateTimeParser().parseDateTime(utcDate); + if (dateTime != null) + return dateTime; + } catch (Exception e) { + debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + } + throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, attrName, utcDate); + } + +} diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java index 97bb78e..6e99b0d 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java @@ -1,6 +1,6 @@ /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * 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.
@@ -55,7 +55,7 @@ import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-@Api
+@Api("CMSO Schedule API")
@Path("/{apiVersion}")
@Produces({MediaType.APPLICATION_JSON})
public interface CMSOService {
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java index c3d61da..d65dd25 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java @@ -261,8 +261,8 @@ public class CMSOServiceImpl extends BaseSchedulerServiceImpl implements CMSOSer if (cw.getEndTime() == null || cw.getEndTime().equals(""))
throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,
"endTime");
- DateTime start = CMSCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
- DateTime end = CMSCallbackImpl.convertISODate(cw.getEndTime(), "endTime");
+ DateTime start = CMSOOptimizerCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
+ DateTime end = CMSOOptimizerCallbackImpl.convertISODate(cw.getEndTime(), "endTime");
if (!end.isAfter(start))
throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_CHANGE_WINDOW,
cw.getStartTime(), cw.getEndTime());
@@ -312,8 +312,8 @@ public class CMSOServiceImpl extends BaseSchedulerServiceImpl implements CMSOSer for (ChangeWindowMessage cw : vnfDetail.getChangeWindow()) {
ChangeManagementChangeWindow cmcw = new ChangeManagementChangeWindow();
cmcw.setChangeManagementGroupsId(cmg.getId());
- DateTime start = CMSCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
- DateTime end = CMSCallbackImpl.convertISODate(cw.getEndTime(), "startTime");
+ DateTime start = CMSOOptimizerCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
+ DateTime end = CMSOOptimizerCallbackImpl.convertISODate(cw.getEndTime(), "startTime");
cmcw.setStartTimeMillis(start.getMillis());
cmcw.setFinishTimeMillis(end.getMillis());
cmChangeWindowDAO.save(cmcw);
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java index 99b4970..cc2785e 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java @@ -1,6 +1,6 @@ /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * 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.
@@ -31,24 +31,23 @@ package org.onap.optf.cmso.service.rs;
-import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
+
import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-@Api
+@Api("CMSO Optimized Schedule API")
@Path("/{apiVersion}")
@Produces({MediaType.APPLICATION_JSON})
public interface CMSOptimizerCallback {
@@ -62,7 +61,6 @@ public interface CMSOptimizerCallback { @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
public Response sniroCallback(
@ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
- @ApiParam(value = "Return schedules > lastScheduleId") CMOptimizerResponse reponse, @Context UriInfo uri,
- @Context HttpServletRequest request);
+ @ApiParam(value = "Return schedules > lastScheduleId") CMOptimizerResponse reponse);
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java index edc2c96..fb69e31 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java @@ -1,6 +1,6 @@ /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * 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.
@@ -31,25 +31,24 @@ package org.onap.optf.cmso.service.rs;
-import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
+
import org.onap.optf.cmso.service.rs.models.HealthCheckMessage;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-@Api
+@Api("CMSO Administration")
@Path("/{apiVersion}")
@Produces({MediaType.APPLICATION_JSON})
public interface HealthCheck {
@@ -63,7 +62,7 @@ public interface HealthCheck { @ApiResponse(code = 400, message = "Not healthy", response = HealthCheckMessage.class)})
public Response healthCheck(@ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
@DefaultValue(value = "true") @ApiParam(value = "Check Interfaces",
- allowMultiple = true) @QueryParam("checkInterfaces") Boolean checkInterfaces,
- @Context UriInfo uri, @Context HttpServletRequest request);
+ allowMultiple = true) @QueryParam("checkInterfaces") Boolean checkInterfaces
+ );
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java index 0877a6b..8e6b09e 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java @@ -34,6 +34,7 @@ package org.onap.optf.cmso.service.rs; import java.util.List;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
@@ -55,11 +56,17 @@ import com.att.eelf.configuration.EELFManager; public class HealthCheckImpl implements HealthCheck {
private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+ @Context
+ UriInfo uri;
+
+ @Context
+ HttpServletRequest request;
+
@Autowired
TmClient tmClient;
@Autowired
- CMSOptimizerClient sniroClient;
+ CMSOptimizerClient optimizerClient;
@Autowired
ApprovalTypeDAO approvalTypeDAO;
@@ -71,7 +78,7 @@ public class HealthCheckImpl implements HealthCheck { MsoStatusClient msoStatusClient;
@Override
- public Response healthCheck(String apiVersion, Boolean checkInterfaces, UriInfo uri, HttpServletRequest request) {
+ public Response healthCheck(String apiVersion, Boolean checkInterfaces) {
debug.debug("Entered healthcheck");
Response response = null;
HealthCheckMessage hc = new HealthCheckMessage();
@@ -80,7 +87,7 @@ public class HealthCheckImpl implements HealthCheck { if (checkInterfaces) {
addToHealthCheckMessage(hc, tmClient.healthCheck());
addToHealthCheckMessage(hc, msoStatusClient.healthCheck());
- addToHealthCheckMessage(hc, sniroClient.healthCheck());
+ addToHealthCheckMessage(hc, optimizerClient.healthCheck());
}
addToHealthCheckMessage(hc, this.healthCheck());
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 ""; + } + +} diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java index b240b61..b2ff6d4 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java @@ -1,6 +1,6 @@ /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * 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.
@@ -59,7 +59,7 @@ import org.onap.optf.cmso.optimizer.bean.CMRequestInfo; import org.onap.optf.cmso.optimizer.bean.CMSchedule;
import org.onap.optf.cmso.optimizer.bean.CMSchedulingInfo;
import org.onap.optf.cmso.optimizer.bean.CMVnfDetails;
-import org.onap.optf.cmso.service.rs.CMSCallbackImpl;
+import org.onap.optf.cmso.service.rs.CMSOOptimizerCallbackImpl;
import org.onap.optf.cmso.wf.bean.WfCmResponse200;
import org.onap.optf.cmso.wf.bean.WfMsoRequestReferences;
import org.onap.optf.cmso.wf.bean.WfMsoResponse;
@@ -101,11 +101,11 @@ public class SchedulerTestLoopbackServiceImpl implements SchedulerTestLoopbackSe nodes.add(sr.getNode());
}
- DateTime startTime = CMSCallbackImpl.convertISODate(si.getStartTime(), "startTime");
+ DateTime startTime = CMSOOptimizerCallbackImpl.convertISODate(si.getStartTime(), "startTime");
// Ignore the finish time for now in the calc. Just accept what they
// gave
- DateTime finishTime = CMSCallbackImpl.convertISODate(si.getEndTime(), "endTime");
+ DateTime finishTime = CMSOOptimizerCallbackImpl.convertISODate(si.getEndTime(), "endTime");
DateTimeFormatter sniroFmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZoneUTC();
int add = si.getAdditionalDurationInSecs();
|