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.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
19 import com.google.common.io.ByteStreams;
20 import java.io.ByteArrayInputStream;
21 import java.io.ByteArrayOutputStream;
22 import java.io.IOException;
23 import java.util.zip.ZipEntry;
24 import java.util.zip.ZipInputStream;
25 import java.util.zip.ZipOutputStream;
27 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
30 * Builds a CBAM VNF package capable to be deployed on ONAP from a CBAM package
32 public class CbamVnfPackageBuilder {
35 * @param originalCbamVnfPackage the original CBAM VNF package
36 * @param vnfdLocation the location of the VNFD within the CBAM VNF package
37 * @param modifiedCbamVnfdContent the modified CBAM VNFD content
40 public byte[] toModifiedCbamVnfPackage(byte[] originalCbamVnfPackage, String vnfdLocation, String modifiedCbamVnfdContent) throws IOException {
41 ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(originalCbamVnfPackage));
42 ByteArrayOutputStream result = new ByteArrayOutputStream();
43 ZipOutputStream out = new ZipOutputStream(result);
45 while ((zipEntry = zipInputStream.getNextEntry()) != null) {
46 if (zipEntry.getName().matches(vnfdLocation)) {
47 out.putNextEntry(new ZipEntry(vnfdLocation));
48 out.write(modifiedCbamVnfdContent.getBytes());
51 out.putNextEntry(new ZipEntry(zipEntry.getName()));
52 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
53 ByteStreams.copy(zipInputStream, byteArrayOutputStream);
54 out.write(byteArrayOutputStream.toByteArray());
58 out.putNextEntry(new ZipEntry("javascript/cbam.pre.collectConnectionPoints.js"));
59 out.write(systemFunctions().loadFile("cbam.pre.collectConnectionPoints.js"));
61 out.putNextEntry(new ZipEntry("javascript/cbam.collectConnectionPoints.js"));
62 out.write(systemFunctions().loadFile("cbam.collectConnectionPoints.js"));
64 out.putNextEntry(new ZipEntry("javascript/cbam.post.collectConnectionPoints.js"));
65 out.write(systemFunctions().loadFile("cbam.post.collectConnectionPoints.js"));
68 zipInputStream.close();
69 return result.toByteArray();