2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.core.tools.main;
23 import static org.openecomp.core.tools.util.Utils.printMessage;
25 import java.time.Duration;
26 import java.time.Instant;
27 import java.util.Optional;
28 import org.openecomp.core.tools.commands.Command;
29 import org.openecomp.core.tools.commands.CommandsHolder;
30 import org.openecomp.sdc.common.session.SessionContextProviderFactory;
31 import org.openecomp.sdc.logging.api.Logger;
32 import org.openecomp.sdc.logging.api.LoggerFactory;
34 public class ZusammenMainTool {
36 private static final Logger LOGGER = LoggerFactory.getLogger(ZusammenMainTool.class);
38 public static void main(String[] args) {
39 Command command = getCommandToRun(args);
41 Instant startTime = Instant.now();
42 SessionContextProviderFactory.getInstance().createInterface().create("GLOBAL_USER", "dox");
43 if (!command.execute(args)) {
47 Instant stopTime = Instant.now();
49 printDuration(command, startTime, stopTime);
53 private static Command getCommandToRun(String[] args) {
54 Optional<Command> command = CommandsHolder.getCommand(args);
55 if (!command.isPresent()) {
56 LOGGER.error("Illegal execution.");
57 CommandsHolder.printUsages();
63 private static void printDuration(Command command, Instant startTime, Instant stopTime) {
64 Duration duration = Duration.between(startTime, stopTime);
65 long minutesPart = duration.toMinutes();
66 long secondsPart = duration.minusMinutes(minutesPart).getSeconds();
68 printMessage(LOGGER, String.format("Zusammen tools command %s finished. Total run time was %s:%s minutes.",
69 command.getCommandName(), minutesPart, secondsPart));