2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.mso.client.sdno;
23 import java.io.FileNotFoundException;
24 import java.io.IOException;
25 import java.util.Optional;
26 import java.util.UUID;
28 import org.onap.aai.domain.yang.GenericVnf;
29 import org.openecomp.mso.client.aai.AAIObjectType;
30 import org.openecomp.mso.client.aai.AAIResourcesClient;
31 import org.openecomp.mso.client.aai.AAIVersion;
32 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
33 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
34 import org.openecomp.mso.client.dmaap.DmaapConsumer;
35 import org.openecomp.mso.client.dmaap.DmaapPublisher;
36 import org.openecomp.mso.client.sdno.beans.Body;
37 import org.openecomp.mso.client.sdno.beans.Input;
38 import org.openecomp.mso.client.sdno.beans.RequestHealthDiagnostic;
39 import org.openecomp.mso.client.sdno.beans.SDNO;
40 import org.openecomp.mso.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer;
41 import org.openecomp.mso.client.sdno.dmaap.SDNOHealthCheckDmaapPublisher;
43 import com.fasterxml.jackson.databind.ObjectMapper;
46 public class SDNOValidatorImpl implements SDNOValidator {
48 private final static String clientName = "MSO";
51 public void healthDiagnostic(String vnfId, UUID uuid, String requestingUserId) throws IOException, Exception {
53 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
54 AAIResourcesClient client = new AAIResourcesClient(AAIVersion.V10, uuid);
55 GenericVnf vnf = client.get(GenericVnf.class, uri);
57 SDNO requestDiagnostic = buildRequestDiagnostic(vnf, uuid, requestingUserId);
58 ObjectMapper mapper = new ObjectMapper();
59 String json = mapper.writeValueAsString(requestDiagnostic);
60 this.submitRequest(json);
61 this.pollForResponse(uuid.toString());
65 protected SDNO buildRequestDiagnostic(GenericVnf vnf, UUID uuid, String requestingUserId) {
67 Optional<String> vnfType;
68 if (vnf.getVnfType() == null) {
69 vnfType = Optional.empty();
71 vnfType = Optional.of(vnf.getVnfType());
73 Input input = new Input();
74 SDNO parentRequest = new SDNO();
75 Body body = new Body();
76 parentRequest.setBody(body);
77 parentRequest.setNodeType(vnfType.orElse("NONE").toUpperCase());
78 parentRequest.setOperation("health-diagnostic");
82 RequestHealthDiagnostic request = new RequestHealthDiagnostic();
83 request.setRequestClientName(clientName);
84 request.setRequestNodeName(vnf.getVnfName());
85 request.setRequestNodeIp(vnf.getIpv4OamAddress()); //generic-vnf oam ip
86 request.setRequestUserId(requestingUserId); //mech id?
87 request.setRequestId(uuid.toString()); //something to identify this request by for polling
89 input.setRequestHealthDiagnostic(request);
93 protected void submitRequest(String json) throws FileNotFoundException, IOException, InterruptedException {
95 DmaapPublisher publisher = new SDNOHealthCheckDmaapPublisher();
98 protected boolean pollForResponse(String uuid) throws Exception {
99 DmaapConsumer consumer = this.getConsumer(uuid);
100 return consumer.consume();
105 protected DmaapConsumer getConsumer(String uuid) throws FileNotFoundException, IOException {
106 return new SDNOHealthCheckDmaapConsumer(uuid);