2 * ============LICENSE_START==============================================
3 * Copyright (c) 2019 AT&T Intellectual Property.
4 * =======================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain a
7 * copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 * ============LICENSE_END=================================================
20 package org.onap.optf.cmso.optimizer.clients.topology;
22 import java.util.Optional;
23 import java.util.UUID;
24 import javax.ws.rs.core.Response.Status;
25 import org.onap.observations.Observation;
26 import org.onap.optf.cmso.common.exceptions.CmsoException;
27 import org.onap.optf.cmso.optimizer.clients.topology.models.TopologyResponse;
28 import org.onap.optf.cmso.optimizer.common.LogMessages;
29 import org.onap.optf.cmso.optimizer.model.Request;
30 import org.onap.optf.cmso.optimizer.model.Topology;
31 import org.onap.optf.cmso.optimizer.model.dao.RequestDao;
32 import org.onap.optf.cmso.optimizer.model.dao.TopologyDao;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.core.env.Environment;
35 import org.springframework.stereotype.Component;
38 public class TopologyRequestManager {
44 RequestDao requestDao;
47 TopologyDao topologyDao;
50 TopologyClient topologyClient;
52 public TopologyResponse createTopologyRequest(UUID uuid)
56 Request request = null;
57 Optional<Request> requestOptional = requestDao.findById(uuid);
58 if (requestOptional.isPresent())
60 request = requestOptional.get();
64 throw new CmsoException(Status.INTERNAL_SERVER_ERROR, LogMessages.EXPECTED_DATA_NOT_FOUND,
65 uuid.toString(), "Request table");
67 Topology topology = null;
68 Optional<Topology> topologyOpt = topologyDao.findById(uuid);
69 if (topologyOpt.isPresent())
71 topology = topologyOpt.get();
76 topology = new Topology();
77 topology.setUuid(uuid);
78 topology.setTopologyRetries(0);
80 TopologyResponse topologyResponse = topologyClient.makeRequest(request, topology);
81 switch(topologyResponse.getStatus())
90 return topologyResponse;
94 Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());