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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Modifications Copyright (c) 2019 Samsung
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.so.client.orchestration;
import java.io.IOException;
import java.util.Optional;
import org.onap.aai.domain.yang.Vserver;
import org.onap.so.bpmn.common.InjectionHelper;
import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIRestClientImpl;
import org.onap.so.client.aai.AAIValidatorImpl;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.aai.mapper.AAIObjectMapper;
import org.onap.so.client.graphinventory.entities.uri.Depth;
import org.onap.so.db.catalog.beans.OrchestrationStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class AAIVnfResources {
@Autowired
private InjectionHelper injectionHelper;
@Autowired
private AAIObjectMapper aaiObjectMapper;
private AAIValidatorImpl aaiValidatorImpl = new AAIValidatorImpl();
public void createVnfandConnectServiceInstance(GenericVnf vnf, ServiceInstance serviceInstance) {
AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
vnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
AAIResourceUri serviceInstanceURI =
AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
injectionHelper.getAaiClient().createIfNotExists(vnfURI, Optional.of(aaiObjectMapper.mapVnf(vnf)))
.connect(vnfURI, serviceInstanceURI);
}
public void createPlatformandConnectVnf(Platform platform, GenericVnf vnf) {
AAIResourceUri platformURI =
AAIUriFactory.createResourceUri(AAIObjectType.PLATFORM, platform.getPlatformName());
AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
injectionHelper.getAaiClient().createIfNotExists(platformURI, Optional.of(platform)).connect(vnfURI,
platformURI);
}
public void createLineOfBusinessandConnectVnf(LineOfBusiness lineOfBusiness, GenericVnf vnf) {
AAIResourceUri lineOfBusinessURI =
AAIUriFactory.createResourceUri(AAIObjectType.LINE_OF_BUSINESS, lineOfBusiness.getLineOfBusinessName());
AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
injectionHelper.getAaiClient().createIfNotExists(lineOfBusinessURI, Optional.of(lineOfBusiness)).connect(vnfURI,
lineOfBusinessURI);
}
public void deleteVnf(GenericVnf vnf) {
AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
injectionHelper.getAaiClient().delete(vnfURI);
}
public void updateOrchestrationStatusVnf(GenericVnf vnf, OrchestrationStatus orchestrationStatus) {
AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
GenericVnf copiedVnf = vnf.shallowCopyId();
vnf.setOrchestrationStatus(orchestrationStatus);
copiedVnf.setOrchestrationStatus(orchestrationStatus);
injectionHelper.getAaiClient().update(vnfURI, aaiObjectMapper.mapVnf(copiedVnf));
}
public void updateObjectVnf(GenericVnf vnf) {
AAIResourceUri vnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
injectionHelper.getAaiClient().update(vnfUri, aaiObjectMapper.mapVnf(vnf));
}
/**
* Retrieve Generic VNF from AAI using vnf Id
*
* @param vnfId - vnf-id required vnf
* @return AAI Generic Vnf
*/
public Optional<org.onap.aai.domain.yang.GenericVnf> getGenericVnf(String vnfId) {
return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.GenericVnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId));
}
/**
* Check inMaint flag value of Generic VNF from AAI using vnf Id
*
* @param vnfId - vnf-id required vnf
* @return inMaint flag value
*/
public boolean checkInMaintFlag(String vnfId) {
org.onap.aai.domain.yang.GenericVnf vnf = injectionHelper.getAaiClient()
.get(org.onap.aai.domain.yang.GenericVnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId))
.orElse(new org.onap.aai.domain.yang.GenericVnf());
return vnf.isInMaint();
}
public void connectVnfToCloudRegion(GenericVnf vnf, CloudRegion cloudRegion) {
AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION,
cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId());
AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
injectionHelper.getAaiClient().connect(vnfURI, cloudRegionURI);
}
public void connectVnfToTenant(GenericVnf vnf, CloudRegion cloudRegion) {
AAIResourceUri tenantURI = AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudRegion.getCloudOwner(),
cloudRegion.getLcpCloudRegionId(), cloudRegion.getTenantId());
AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
injectionHelper.getAaiClient().connect(tenantURI, vnfURI);
}
public boolean checkVnfClosedLoopDisabledFlag(String vnfId) {
org.onap.aai.domain.yang.GenericVnf vnf = injectionHelper.getAaiClient()
.get(org.onap.aai.domain.yang.GenericVnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId))
.orElse(new org.onap.aai.domain.yang.GenericVnf());
return vnf.isIsClosedLoopDisabled();
}
public boolean checkVnfPserversLockedFlag(String vnfId) throws IOException {
org.onap.aai.domain.yang.GenericVnf vnf = injectionHelper.getAaiClient()
.get(org.onap.aai.domain.yang.GenericVnf.class,
AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId))
.orElse(new org.onap.aai.domain.yang.GenericVnf());
AAIRestClientImpl client = new AAIRestClientImpl();
aaiValidatorImpl.setClient(client);
return aaiValidatorImpl.isPhysicalServerLocked(vnf.getVnfId());
}
public boolean checkNameInUse(String vnfName) {
AAIResourceUri vnfUri =
AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName);
return injectionHelper.getAaiClient().exists(vnfUri);
}
public AAIResultWrapper queryVnfWrapperById(GenericVnf vnf) {
AAIResourceUri uri =
AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()).depth(Depth.ALL);
return injectionHelper.getAaiClient().get(uri);
}
public Optional<Vserver> getVserver(AAIResourceUri uri) {
return injectionHelper.getAaiClient().get(uri).asBean(Vserver.class);
}
}
|