2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.config.assignment.processor;
\r
20 import java.util.List;
\r
21 import java.util.Map;
\r
22 import org.apache.commons.lang3.StringUtils;
\r
23 import org.onap.ccsdk.config.assignment.service.ConfigAssignmentUtils;
\r
24 import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;
\r
25 import org.onap.ccsdk.config.model.ConfigModelConstant;
\r
26 import org.onap.ccsdk.config.model.ConfigModelException;
\r
27 import org.onap.ccsdk.config.model.data.ResourceAssignment;
\r
28 import org.onap.ccsdk.config.model.service.ComponentNode;
\r
29 import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;
\r
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
\r
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
\r
33 public class DefaultResourceProcessor implements ComponentNode {
\r
35 public DefaultResourceProcessor(ConfigResourceService configResourceService) {}
\r
38 public Boolean preCondition(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
39 throws SvcLogicException {
\r
40 return Boolean.TRUE;
\r
44 public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
45 throws SvcLogicException {
\r
46 // Auto-generated method stub
\r
50 public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
\r
51 // Auto-generated method stub
\r
54 @SuppressWarnings("unchecked")
\r
56 public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
57 throws SvcLogicException {
\r
59 List<ResourceAssignment> batchResourceAssignment =
\r
60 (List<ResourceAssignment>) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS);
\r
62 if (batchResourceAssignment != null && !batchResourceAssignment.isEmpty()) {
\r
63 for (ResourceAssignment resourceAssignment : batchResourceAssignment) {
\r
64 processResourceAssignment(ctx, componentContext, resourceAssignment);
\r
67 } catch (Exception e) {
\r
68 throw new SvcLogicException(String.format("DefaultResourceProcessor Exception : (%s)", e), e);
\r
73 private void processResourceAssignment(SvcLogicContext ctx, Map<String, Object> componentContext,
\r
74 ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException {
\r
75 if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName())
\r
76 && resourceAssignment.getProperty() != null) {
\r
78 // Check if It has Input
\r
79 Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName());
\r
80 if (value == null) {
\r
81 value = resourceAssignment.getProperty().getDefaultValue();
\r
84 // if value is null don't call setResourceDataValue to populate the value
\r
85 if (value != null) {
\r
86 ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);
\r
89 // Check the value has populated for mandatory case
\r
90 ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment);
\r
91 } catch (Exception e) {
\r
92 ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment,
\r
94 throw new SvcLogicException(
\r
95 String.format("Failed in template key (%s) assignments with : (%s)", resourceAssignment, e), e);
\r
101 public void postProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
\r
102 throws SvcLogicException {
\r
103 // Auto-generated method stub
\r