summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/openecomp/vid/services/ChangeManagementServiceImpl.java
blob: 7e69d8fece0a33a7ab0526a9677784bc3ab5d653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.openecomp.vid.services;

import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.openecomp.vid.changeManagement.ChangeManagementRequest;
import org.openecomp.vid.changeManagement.RequestDetails;
import org.openecomp.vid.mso.MsoBusinessLogic;
import org.openecomp.vid.mso.MsoResponseWrapper;
import org.openecomp.vid.controller.MsoController;
import org.openecomp.portalsdk.core.util.SystemProperties;
import org.openecomp.vid.scheduler.*;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.openecomp.vid.mso.rest.Request;
import org.springframework.stereotype.Service;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;

import java.util.Date;
import java.util.List;
import java.util.Collection;


@Service
public class ChangeManagementServiceImpl implements ChangeManagementService {
    @Override
    public Collection<Request> getMSOChangeManagements() {
        Collection<Request> result = null;
		MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogic();
		try {
            result = msoBusinessLogic.getOrchestrationRequestsForDashboard();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    private RequestDetails findRequestByVnfName(List<RequestDetails> requests, String vnfName){

    	if (requests == null)
    		return null;

    	for(RequestDetails requestDetails: requests){
			if(requestDetails.getVnfName().equals(vnfName)){
				return requestDetails;
			}
		}

		return null;
	}

	@Override
	public ResponseEntity<String> doChangeManagement(ChangeManagementRequest request, String vnfName) {
		if (request == null)
			return null;
		ResponseEntity<String> response = null;
		RequestDetails currentRequestDetails = findRequestByVnfName(request.getRequestDetails(), vnfName);
		MsoResponseWrapper msoResponseWrapperObject = null;
		if(currentRequestDetails != null){
			MsoBusinessLogic msoBusinessLogicObject = new MsoBusinessLogic();
			String serviceInstanceId = currentRequestDetails.getRelatedInstList().get(0).getRelatedInstance().getInstanceId();
			String vnfInstanceId = currentRequestDetails.getVnfInstanceId();
			try {
				if (request.getRequestType().equalsIgnoreCase("update")) {
					
					 msoResponseWrapperObject = msoBusinessLogicObject.updateVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId);
				}
				else if (request.getRequestType().equalsIgnoreCase("replace"))
				{
					msoResponseWrapperObject = msoBusinessLogicObject.replaceVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId);
//					throw new NotImplementedException();
				}
				response = new ResponseEntity<String>(msoResponseWrapperObject.getResponse(), HttpStatus.OK);
				return response;
			} catch (Exception e) {
				e.printStackTrace();
			}

		}

		// AH:TODO: return ChangeManagementResponse
		return null;
	}

    @Override
    public JSONArray getSchedulerChangeManagements() {
        JSONArray result = null;
        try {
            String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_GET_SCHEDULES);
            org.openecomp.vid.scheduler.RestObject<String> restObject = new org.openecomp.vid.scheduler.RestObject<>();
            SchedulerRestInterfaceIfc restClient = SchedulerRestInterfaceFactory.getInstance();

            String str = new String();
            restObject.set(str);
            restClient.Get(str, "", path, restObject);
            String restCallResult = restObject.get();
            JSONParser parser = new JSONParser();
            Object parserResult = parser.parse(restCallResult);
            result = (JSONArray) parserResult;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }


}