2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.sdc.asdctool.main;
23 import fj.data.Either;
24 import org.openecomp.sdc.asdctool.cli.CLIToolData;
25 import org.openecomp.sdc.asdctool.cli.SpringCLITool;
26 import org.openecomp.sdc.asdctool.configuration.GetConsumersConfiguration;
27 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
28 import org.openecomp.sdc.be.model.operations.impl.ConsumerOperation;
29 import org.openecomp.sdc.be.resources.data.ConsumerData;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import java.util.List;
35 public class GetConsumersMenu extends SpringCLITool {
37 private static final Logger LOGGER = LoggerFactory.getLogger(GetConsumersMenu.class);
39 public static void main(String[] args) {
40 GetConsumersMenu getConsumersMenu = new GetConsumersMenu();
41 CLIToolData cliToolData = getConsumersMenu.init(args);
42 ConsumerOperation consumersService = cliToolData.getSpringApplicationContext().getBean(ConsumerOperation.class);
43 printConsumers(getConsumersMenu, consumersService);
46 private static void printConsumers(GetConsumersMenu getConsumersMenu, ConsumerOperation consumersService) {
47 Either<List<ConsumerData>, StorageOperationStatus> allConsumers = consumersService.getAll();
48 allConsumers.left().foreachDoEffect(getConsumersMenu::printConsumers);
49 allConsumers.right().foreachDoEffect(getConsumersMenu::printErr);
52 private void printConsumers(List<ConsumerData> consumers) {
53 System.out.println("SDC consumers: ");
54 consumers.forEach(consumer -> {
55 System.out.println("#########################");
56 System.out.println(consumer);
61 private void printErr(StorageOperationStatus err) {
62 String errMsg = String.format("failed to fetch consumers. reason: %s", err);
64 System.err.print(errMsg);
69 protected String commandName() {
70 return "get-consumers";
74 protected Class<?> getSpringConfigurationClass() {
75 return GetConsumersConfiguration.class;