3120e0d6bce71ebf94b2ba25caf9414f5c48e4e8
[optf/cmso.git] /
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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=================================================
17  *
18  */
19
20 package org.onap.optf.cmso.optimizer.clients.topology;
21
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;
36
37 @Component
38 public class TopologyRequestManager {
39
40     @Autowired
41     Environment env;
42
43     @Autowired
44     RequestDao requestDao;
45
46     @Autowired
47     TopologyDao topologyDao;
48
49     @Autowired
50     TopologyClient topologyClient;
51
52     public TopologyResponse createTopologyRequest(UUID uuid)
53     {
54         try
55         {
56             Request request = null;
57             Optional<Request> requestOptional = requestDao.findById(uuid);
58             if (requestOptional.isPresent())
59             {
60                 request = requestOptional.get();
61             }
62             if (request == null)
63             {
64                 throw new CmsoException(Status.INTERNAL_SERVER_ERROR, LogMessages.EXPECTED_DATA_NOT_FOUND,
65                                 uuid.toString(), "Request table");
66             }
67             Topology topology  = null;
68             Optional<Topology> topologyOpt  = topologyDao.findById(uuid);
69             if (topologyOpt.isPresent())
70             {
71                 topology = topologyOpt.get();
72
73             }
74             if (topology == null)
75             {
76                 topology = new Topology();
77                 topology.setUuid(uuid);
78                 topology.setTopologyRetries(0);
79             }
80             TopologyResponse topologyResponse = topologyClient.makeRequest(request, topology);
81             switch(topologyResponse.getStatus())
82             {
83                 case COMPLETED:
84                     break;
85                 case FAILED:
86                     break;
87                 case IN_PROGRESS:
88                     break;
89             }
90             return topologyResponse;
91         }
92         catch (Exception e)
93         {
94             Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
95         }
96         return null;
97
98     }
99
100 }