2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
18 import com.google.common.base.Splitter;
19 import org.onap.aai.domain.yang.v11.RelationshipList;
20 import org.onap.aai.domain.yang.v11.Vnfc;
21 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
22 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
26 import org.slf4j.Logger;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.context.annotation.Conditional;
29 import org.springframework.stereotype.Component;
31 import static java.lang.String.format;
32 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
33 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
36 * Responsible for managing {@link Vnfc} in AAI
39 @Conditional(value = Conditions.UseForDirect.class)
40 public class VnfcManager extends AbstractManager {
41 private static Logger logger = org.slf4j.LoggerFactory.getLogger(VnfcManager.class);
44 VnfcManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
45 super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
48 public static String buildUrl(String vnfId, String cbamVnfcId) {
49 return format("/vnfcs/vnfc/%s", buildId(vnfId, cbamVnfcId));
52 public static String getCbamVnfcId(String vnfcId) {
53 String vnfId = Splitter.on(CbamUtils.SEPARATOR).split(vnfcId).iterator().next();
54 return vnfcId.replaceFirst(vnfId + SEPARATOR, "");
57 private static String buildId(String vnfId, String cbamVnfcId) {
58 return vnfId + SEPARATOR + cbamVnfcId;
62 protected Logger getLogger() {
66 void delete(String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc) {
67 aaiRestApiProvider.delete(logger, NETWORK, buildUrl(vnfId, cbamVnfc.getId()));
70 void update(String vimId, String tenantId, String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc, boolean inMaintenance) {
71 String url = buildUrl(vnfId, cbamVnfc.getId());
72 Vnfc vnfc = createOrGet(NETWORK, url, OBJECT_FACTORY.createVnfc());
73 updateFields(vimId, tenantId, vnfc, cbamVnfc, vnfId, url, inMaintenance);
76 private void updateFields(String vimId, String tenantId, Vnfc aaiVnfc, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc, String vnfId, String url, boolean inMaintenance) {
77 aaiVnfc.setInMaint(inMaintenance);
78 aaiVnfc.setIsClosedLoopDisabled(inMaintenance);
79 //FIXME would be good to know what is this mandatory parameter
80 aaiVnfc.setNfcFunction(cbamVnfc.getId());
81 //FIXME would be good to know what is this mandatory parameter
82 aaiVnfc.setNfcNamingCode(cbamVnfc.getId());
83 aaiVnfc.setVnfcName(buildId(vnfId, cbamVnfc.getId()));
84 aaiVnfc.setRelationshipList(new RelationshipList());
85 addSingletonRelation(aaiVnfc.getRelationshipList(), VserverManager.linkTo(vimId, tenantId, cbamVnfc.getComputeResource().getResourceId()));
86 addSingletonRelation(aaiVnfc.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
87 aaiRestApiProvider.put(logger, NETWORK, url, aaiVnfc, Void.class);