2 * Copyright 2018 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.cli.fw.cmd.product;
19 import java.io.InputStream;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.List;
26 import org.onap.cli.fw.cmd.OnapCommand;
27 import org.onap.cli.fw.conf.OnapCommandConstants;
28 import org.onap.cli.fw.error.OnapCommandException;
29 import org.onap.cli.fw.schema.OnapCommandSchema;
30 import org.onap.cli.fw.schema.OnapCommandSchemaInfo;
31 import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
37 @OnapCommandSchema(schema = "service-list.yaml")
38 public class OnapServiceListCommand extends OnapCommand {
41 protected void run() throws OnapCommandException {
43 String product = getParametersMap().get("product").getValue().toString();
45 List<OnapCommandSchemaInfo> schemas = OnapCommandDiscoveryUtils.discoverOrLoadSchemas(false);
46 Map<String, Set<String>> rslt = new HashMap<>();
48 for (OnapCommandSchemaInfo schema : schemas) {
49 if (schema.isIgnore()) {
53 if (!rslt.containsKey(schema.getProduct())) {
54 rslt.put(schema.getProduct(), new HashSet<String>());
56 rslt.get(schema.getProduct()).add(schema.getService());
59 InputStream stream = this.getClass().getResourceAsStream("/" +OnapCommandConstants.SCHEMA_DIRECTORY +
60 "/" + product + OnapCommandConstants.PRODUCT_REGISTRY_YAML);
62 Map<String, String> serviceDescs = new HashMap<>();
64 Map<String, ?> map = OnapCommandDiscoveryUtils.loadYaml(stream);
65 if (map.containsKey("services")) {
66 List<Map<String, String>> services = (List) map.get("services");
68 for (Map<String, String> service: services ) {
69 serviceDescs.put(service.get("name"), service.get("description"));
74 for (String service : rslt.getOrDefault(product, new HashSet<String>())) {
75 this.getResult().getRecordsMap().get("product").getValues().add(product);
76 this.getResult().getRecordsMap().get("service").getValues().add(service);
77 this.getResult().getRecordsMap().get("description").getValues().add(
78 serviceDescs.containsKey(service) ? serviceDescs.get(service) : "");