59af31f4fc94729d342a93bca30cd986b00cb245
[policy/models.git] /
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.VirtualControlLoopEvent;
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     /**
37      * Constructs the object.
38      *
39      * @param actorName name of the actor with which this operator is associated
40      */
41     public RerouteOperator(String actorName) {
42         super(actorName, NAME);
43     }
44
45     @Override
46     protected SdncRequest constructRequest(VirtualControlLoopEvent onset) {
47         String serviceInstance = onset.getAai().get("service-instance.service-instance-id");
48         if (StringUtils.isBlank(serviceInstance)) {
49             throw new IllegalArgumentException("missing enrichment data, service-instance-id");
50         }
51         SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
52         serviceInfo.setServiceInstanceId(serviceInstance);
53
54         String networkId = onset.getAai().get("network-information.network-id");
55         if (StringUtils.isBlank(networkId)) {
56             throw new IllegalArgumentException("missing enrichment data, network-id");
57         }
58         SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();
59         networkInfo.setNetworkId(networkId);
60
61         SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
62         requestInfo.setRequestAction("ReoptimizeSOTNInstance");
63
64         SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
65         headerInfo.setSvcAction("reoptimize");
66         headerInfo.setSvcRequestId(UUID.randomUUID().toString());
67
68         SdncRequest request = new SdncRequest();
69         request.setNsInstanceId(serviceInstance);
70         request.setRequestId(onset.getRequestId());
71         request.setUrl("/GENERIC-RESOURCE-API:network-topology-operation");
72
73         SdncHealRequest healRequest = new SdncHealRequest();
74         healRequest.setRequestHeaderInfo(headerInfo);
75         healRequest.setNetworkInfo(networkInfo);
76         healRequest.setRequestInfo(requestInfo);
77         healRequest.setServiceInfo(serviceInfo);
78         request.setHealRequest(healRequest);
79         return request;
80     }
81 }