Allow storing database password in environment variables
[policy/models.git] / models-interactions / model-actors / actor.sdnc / src / main / java / org / onap / policy / controlloop / actor / sdnc / RerouteOperator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.sdnc;
22
23 import java.util.UUID;
24 import org.apache.commons.lang3.StringUtils;
25 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
26 import org.onap.policy.sdnc.SdncHealNetworkInfo;
27 import org.onap.policy.sdnc.SdncHealRequest;
28 import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
29 import org.onap.policy.sdnc.SdncHealRequestInfo;
30 import org.onap.policy.sdnc.SdncHealServiceInfo;
31 import org.onap.policy.sdnc.SdncRequest;
32
33 public class RerouteOperator extends SdncOperator {
34     public static final String NAME = "Reroute";
35
36     public static final String URI = "/GENERIC-RESOURCE-API:network-topology-operation";
37
38     // fields in the enrichment data
39     public static final String SERVICE_ID_KEY = "service-instance.service-instance-id";
40     public static final String NETWORK_ID_KEY = "network-information.network-id";
41
42     /**
43      * Constructs the object.
44      *
45      * @param actorName name of the actor with which this operator is associated
46      */
47     public RerouteOperator(String actorName) {
48         super(actorName, NAME);
49     }
50
51     @Override
52     protected SdncRequest constructRequest(ControlLoopEventContext context) {
53         String serviceInstance = context.getEnrichment().get(SERVICE_ID_KEY);
54         if (StringUtils.isBlank(serviceInstance)) {
55             throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY);
56         }
57         SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
58         serviceInfo.setServiceInstanceId(serviceInstance);
59
60         String networkId = context.getEnrichment().get(NETWORK_ID_KEY);
61         if (StringUtils.isBlank(networkId)) {
62             throw new IllegalArgumentException("missing enrichment data, " + NETWORK_ID_KEY);
63         }
64         SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();
65         networkInfo.setNetworkId(networkId);
66
67         SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
68         requestInfo.setRequestAction("ReoptimizeSOTNInstance");
69
70         SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
71         headerInfo.setSvcAction("reoptimize");
72         headerInfo.setSvcRequestId(UUID.randomUUID().toString());
73
74         SdncRequest request = new SdncRequest();
75         request.setNsInstanceId(serviceInstance);
76         request.setRequestId(context.getRequestId());
77         request.setUrl(URI);
78
79         SdncHealRequest healRequest = new SdncHealRequest();
80         healRequest.setRequestHeaderInfo(headerInfo);
81         healRequest.setNetworkInfo(networkInfo);
82         healRequest.setRequestInfo(requestInfo);
83         healRequest.setServiceInfo(serviceInfo);
84         request.setHealRequest(healRequest);
85         return request;
86     }
87 }