2  * ============LICENSE_START=======================================================
 
   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
 
  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.onap.policy.controlloop.actor.sdnc;
 
  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;
 
  33 public class RerouteOperator extends SdncOperator {
 
  34     public static final String NAME = "Reroute";
 
  36     public static final String URI = "/GENERIC-RESOURCE-API:network-topology-operation";
 
  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";
 
  43      * Constructs the object.
 
  45      * @param actorName name of the actor with which this operator is associated
 
  47     public RerouteOperator(String actorName) {
 
  48         super(actorName, NAME);
 
  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);
 
  57         SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
 
  58         serviceInfo.setServiceInstanceId(serviceInstance);
 
  60         String networkId = context.getEnrichment().get(NETWORK_ID_KEY);
 
  61         if (StringUtils.isBlank(networkId)) {
 
  62             throw new IllegalArgumentException("missing enrichment data, " + NETWORK_ID_KEY);
 
  64         SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();
 
  65         networkInfo.setNetworkId(networkId);
 
  67         SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
 
  68         requestInfo.setRequestAction("ReoptimizeSOTNInstance");
 
  70         SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
 
  71         headerInfo.setSvcAction("reoptimize");
 
  72         headerInfo.setSvcRequestId(UUID.randomUUID().toString());
 
  74         SdncRequest request = new SdncRequest();
 
  75         request.setNsInstanceId(serviceInstance);
 
  76         request.setRequestId(context.getRequestId());
 
  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);