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.controlloop.actorserviceprovider.impl.HttpOperator;
 
  27 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
 
  28 import org.onap.policy.sdnc.SdncHealNetworkInfo;
 
  29 import org.onap.policy.sdnc.SdncHealRequest;
 
  30 import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
 
  31 import org.onap.policy.sdnc.SdncHealRequestInfo;
 
  32 import org.onap.policy.sdnc.SdncHealServiceInfo;
 
  33 import org.onap.policy.sdnc.SdncRequest;
 
  35 public class RerouteOperation extends SdncOperation {
 
  36     public static final String NAME = "Reroute";
 
  38     public static final String URI = "/GENERIC-RESOURCE-API:network-topology-operation";
 
  40     // fields in the enrichment data
 
  41     public static final String SERVICE_ID_KEY = "service-instance.service-instance-id";
 
  42     public static final String NETWORK_ID_KEY = "network-information.network-id";
 
  45      * Constructs the object.
 
  47      * @param params operation parameters
 
  48      * @param operator operator that created this operation
 
  50     public RerouteOperation(ControlLoopOperationParams params, HttpOperator operator) {
 
  51         super(params, operator);
 
  55     protected SdncRequest makeRequest(int attempt) {
 
  56         ControlLoopEventContext context = params.getContext();
 
  58         String serviceInstance = context.getEnrichment().get(SERVICE_ID_KEY);
 
  59         if (StringUtils.isBlank(serviceInstance)) {
 
  60             throw new IllegalArgumentException("missing enrichment data, " + SERVICE_ID_KEY);
 
  62         SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
 
  63         serviceInfo.setServiceInstanceId(serviceInstance);
 
  65         String networkId = context.getEnrichment().get(NETWORK_ID_KEY);
 
  66         if (StringUtils.isBlank(networkId)) {
 
  67             throw new IllegalArgumentException("missing enrichment data, " + NETWORK_ID_KEY);
 
  69         SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();
 
  70         networkInfo.setNetworkId(networkId);
 
  72         SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
 
  73         requestInfo.setRequestAction("ReoptimizeSOTNInstance");
 
  75         SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
 
  76         headerInfo.setSvcAction("reoptimize");
 
  77         headerInfo.setSvcRequestId(UUID.randomUUID().toString());
 
  79         SdncRequest request = new SdncRequest();
 
  80         request.setNsInstanceId(serviceInstance);
 
  81         request.setRequestId(context.getRequestId());
 
  84         SdncHealRequest healRequest = new SdncHealRequest();
 
  85         healRequest.setRequestHeaderInfo(headerInfo);
 
  86         healRequest.setNetworkInfo(networkInfo);
 
  87         healRequest.setRequestInfo(requestInfo);
 
  88         healRequest.setServiceInfo(serviceInfo);
 
  89         request.setHealRequest(healRequest);