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 io.reactivex.Observable;
19 import java.util.ArrayList;
20 import org.onap.aai.model.Vnfc;
21 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
22 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProviderForSo;
23 import org.slf4j.Logger;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Component;
27 import static com.google.common.base.Splitter.on;
28 import static com.google.common.collect.Lists.newArrayList;
29 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
32 * Responsible for managing {@link Vnfc} in AAI
35 public class VnfcManager extends AbstractManager {
36 private static Logger logger = org.slf4j.LoggerFactory.getLogger(VnfcManager.class);
39 VnfcManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProviderForSo cbamRestApiProvider) {
40 super(aaiRestApiProvider, cbamRestApiProvider);
43 private static String buildId(String vnfId, String cbamVnfcId) {
44 return vnfId + SEPARATOR + cbamVnfcId;
48 * @param onapVnfcId the identifier of the VNFC in AAI
49 * @return the identifier of the VNFC in CBAM
51 public static String buildCbamId(String onapVnfcId) {
52 return newArrayList(on(SEPARATOR).split(onapVnfcId)).get(1);
56 protected Logger getLogger() {
60 void delete(String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc) {
61 Vnfc vnfc = getVnfc(buildId(vnfId, cbamVnfc.getId())).blockingFirst();
62 aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion()).blockingFirst();
65 private Observable<Vnfc> getVnfc(String vnfcId) {
66 return aaiRestApiProvider.getNetworkApi().getNetworkVnfcsVnfc(vnfcId, null, null, null, null, null, null, null, null, null);
69 void update(String vimId, String tenantId, String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc, boolean inMaintenance) {
70 Vnfc vnfc = createOrGet(getVnfc(buildId(vnfId, cbamVnfc.getId())), new Vnfc());
71 updateFields(vimId, tenantId, vnfc, cbamVnfc, vnfId, inMaintenance);
74 private void updateFields(String vimId, String tenantId, Vnfc aaiVnfc, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc, String vnfId, boolean inMaintenance) {
75 aaiVnfc.setInMaint(inMaintenance);
76 aaiVnfc.setIsClosedLoopDisabled(inMaintenance);
77 //FIXME would be good to know what is this mandatory parameter
78 aaiVnfc.setNfcFunction(cbamVnfc.getId());
79 //FIXME would be good to know what is this mandatory parameter
80 aaiVnfc.setNfcNamingCode(cbamVnfc.getId());
81 aaiVnfc.setVnfcName(buildId(vnfId, cbamVnfc.getId()));
82 if (aaiVnfc.getRelationshipList() == null) {
83 aaiVnfc.setRelationshipList(new ArrayList<>());
85 addSingletonRelation(aaiVnfc.getRelationshipList(), VserverManager.linkTo(vimId, tenantId, cbamVnfc.getComputeResource().getResourceId()));
86 addSingletonRelation(aaiVnfc.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
87 aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc).blockingFirst();