transformedPort.macAddress = port.attributes.mac_address;
transformedPort.serverProviderId = port.attributes.device_id;
transformedPort.networkProviderId = port.attributes.network_id;
- transformedPort.changeType = 'untouched';
- var added = contains(diff.add, path);
- var removed = contains(diff.remove, path);
- if(added && removed){
- transformedPort.changeType = "MODIFIED";
- }
- else{
- if(removed){
- transformedPort.changeType = "REMOVED";
- }
- if(added){
- transformedPort.changeType = "ADDED";
- }
- }
- if('untouched' != transformedPort.changeType && managedPort){
+ if(managedPort){
transformedPorts.push(transformedPort)
}
})
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
+import java.io.IOException;
+
+import static org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION;
+import static org.springframework.http.HttpHeaders.CONTENT_LENGTH;
+import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
+import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.TEXT_HTML_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
logger.info("REST: convert package");
Part part = request.getParts().iterator().next();
byte[] bytes = vnfPackageConverter.covert(part.getInputStream());
- httpResponse.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_OCTET_STREAM.getMimeType());
- httpResponse.setStatus(HttpStatus.OK.value());
- httpResponse.addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
- httpResponse.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + "core.csar" + "\"");
+ httpResponse.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM.getMimeType());
+ httpResponse.setStatus(OK.value());
+ httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length));
+ httpResponse.addHeader(CONTENT_DISPOSITION, "attachment; filename=\"" + "core.csar" + "\"");
httpResponse.getOutputStream().write(bytes);
httpResponse.getOutputStream().flush();
}
*/
@RequestMapping(value = "/convert", method = GET, produces = TEXT_HTML_VALUE)
@ResponseBody
- public void getUploadPageForConvertingVnfd(HttpServletResponse httpResponse) throws Exception {
+ public void getUploadPageForConvertingVnfd(HttpServletResponse httpResponse) throws IOException {
logger.info("REST: get converter main page");
byte[] bytes = systemFunctions().loadFile("upload.html");
- httpResponse.addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
+ httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length));
httpResponse.getOutputStream().write(bytes);
}
}
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.springframework.http.HttpHeaders.CONTENT_LENGTH;
+import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
+import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
/**
*/
@RequestMapping(value = "/swagger.json", method = GET)
@ResponseBody
- public void getSwaggerApiDefinition(HttpServletResponse httpResponse) throws Exception {
+ public void getSwaggerApiDefinition(HttpServletResponse httpResponse) throws IOException {
logger.info("REST: get swagger definition");
- httpResponse.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
+ httpResponse.addHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE);
byte[] bytes = selfRegistrationManager.getSwaggerApiDefinition();
- httpResponse.addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
+ httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length));
httpResponse.getOutputStream().write(bytes);
}
}
import com.google.gson.JsonObject;
import org.slf4j.Logger;
+/**
+ * Collection of utility functions
+ */
public class CbamUtils {
+ private static class OperationMustBeAborted extends RuntimeException{
+ OperationMustBeAborted(String msg){
+ super(msg);
+ }
+ OperationMustBeAborted(Exception e, String msg){
+ super(msg, e);
+ }
+ }
+
private CbamUtils() {
//use static way
}
public static JsonElement childElement(JsonObject parent, String name) {
JsonElement child = parent.get(name);
if (child == null) {
- throw new RuntimeException("Missing child " + name);
+ throw new OperationMustBeAborted("Missing child " + name);
}
return child;
}
*/
public static RuntimeException fatalFailure(Logger logger, String msg, Exception e) {
logger.error(msg, e);
- throw new RuntimeException(msg, e);
+ throw new OperationMustBeAborted(e, msg);
}
/**
*/
public static RuntimeException fatalFailure(Logger logger, String msg) {
logger.error(msg);
- throw new RuntimeException(msg);
+ throw new OperationMustBeAborted(msg);
}
}
import org.apache.commons.codec.binary.Base64;
+import javax.swing.text.html.Option;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.KeyFactory;
import java.util.Optional;
import java.util.Set;
+import static java.util.Optional.empty;
+import static java.util.Optional.of;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.fatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
/**
*/
public final class StoreLoader {
- public static final String PASSWORD = "password";
+ public static final String PASS_ALIAS = "password";
private static final String RSA = "RSA";
private static final String X_509 = "X.509";
private static final String SUN = "SUN";
if (rindex == -1 || lindex == -1) {
return "";
}
- String substring = content.substring(rindex, lindex) + end(scope);
- return substring;
+ return content.substring(rindex, lindex) + end(scope);
}
/**
*/
public static KeyStore loadStore(String pem, String storePassword, String keyPassword) {
Optional<PrivateKey> privateKey = generatePrivateKey(pem);
- Certificate[] certs = createCertificates(pem);
+ Optional<Certificate[]> certs = createCertificates(pem);
try {
KeyStore ks = KeyStore.getInstance(JKS, SUN);
ks.load(null, storePassword.toCharArray());
if (privateKey.isPresent()) {
- ks.setKeyEntry(PASSWORD, privateKey.get(), keyPassword.toCharArray(), certs);
- } else if (certs != null) {
+ ks.setKeyEntry(PASS_ALIAS, privateKey.get(), keyPassword.toCharArray(), certs.orElse(null));
+ } else if (certs.isPresent()) {
int index = 0;
- for (Certificate cert : certs) {
+ for (Certificate cert : certs.get()) {
TrustedCertificateEntry ts = new TrustedCertificateEntry(cert);
- ks.setEntry(PASSWORD + index, ts, null);
+ ks.setEntry(PASS_ALIAS + index, ts, null);
index++;
}
}
}
}
- private static Certificate[] createCertificates(String pem) {
+ private static Optional<Certificate[]> createCertificates(String pem) {
Set<Certificate> certificates = new HashSet<>();
try {
for (String certificate : getCertifacates(pem)) {
certificates.addAll(c);
}
} catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new RuntimeException("Unable to load certificates", e);
+ throw fatalFailure(logger, "Unable to load certificates", e);
}
if (certificates.size() > 0) {
- return certificates.toArray(new Certificate[certificates.size()]);
+ return of(certificates.toArray(new Certificate[certificates.size()]));
} else {
- return null;
+ return empty();
}
}
if (!key.isEmpty()) {
KeyFactory keyFactory = KeyFactory.getInstance(RSA);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(toDer(key, RSA_PRIVATE_KEY));
- return Optional.of(keyFactory.generatePrivate(keySpec));
+ return of(keyFactory.generatePrivate(keySpec));
}
- return Optional.empty();
+ return empty();
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
- logger.error("Unable to load key", e);
- throw new RuntimeException("Unable to load key", e);
+ throw fatalFailure(logger, "Unable to load key", e);
}
}
* the classes that uses static calls.
*/
public class SystemFunctions {
- private static SystemFunctions INSTANCE;
+ private static SystemFunctions singletonInstance;
/**
* @return singleton instance
*/
public static SystemFunctions systemFunctions() {
- if (INSTANCE != null) {
- return INSTANCE;
+ if (singletonInstance != null) {
+ return singletonInstance;
} else {
synchronized (SystemFunctions.class) {
- INSTANCE = new SystemFunctions();
+ singletonInstance = new SystemFunctions();
}
- return INSTANCE;
+ return singletonInstance;
}
}
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
* destination that is typically not continuously monitored.
*/
public PrintStream err() {
- return System.err;
+ return System.err; //NO SONAR (intentional wrapping of system err
}
/**
* @see java.io.PrintStream#println(java.lang.String)
*/
public PrintStream out() {
- return System.out;
+ return System.out; //NO SONAR (intentional wrapping of system out)
}
/**
* the host environment or user.
*/
public InputStream in() {
- return System.in;
+ return System.in; //NO SONAR (intentional wrapping of system in)
}
/**
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.NokiaSvnfmApplication;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
* It takes parameters from application-real.properties
*/
@Test
- public void testBasicWorkflow() throws Exception {
-
-
- Thread.sleep(10000000 * 1000L);
+ public void testBasicWorkflow() {
+ SystemFunctions.systemFunctions().sleep(10000000 * 1000L);
}
}
assertEquals(expectedVnfmInfo, vnfmInfo);
//when
//sleeping is required to make time pass (for cache to notice the change)
- Thread.sleep(10);
+ //cache is configured with 1 ms cache eviction without sleep it is not
+ //deterministic that at least 1 ms time will pass between calls
+ Thread.sleep(10); //NO SONAR
VnfmInfo vnfmInfo2 = genericExternalSystemInfoProvider.getVnfmInfo(VNFM_ID);
//verify source system called again
verify(logger, times(2)).info("Quering VNFM info from source with " + VNFM_ID + " identifier");
@Before
public void genericSetup() throws Exception {
MockitoAnnotations.initMocks(this);
- ReflectionTestUtils.setField(SystemFunctions.class, "INSTANCE", systemFunctions);
+ ReflectionTestUtils.setField(SystemFunctions.class, "singletonInstance", systemFunctions);
when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID)).thenReturn(vnfApi);
when(cbamRestApiProvider.getCbamOperationExecutionApi(VNFM_ID)).thenReturn(operationExecutionApi);
when(cbamRestApiProvider.getCbamLcnApi(VNFM_ID)).thenReturn(lcnApi);
@After
public void tearGeneric() {
- ReflectionTestUtils.setField(SystemFunctions.class, "INSTANCE", null);
+ ReflectionTestUtils.setField(SystemFunctions.class, "singletonInstance", null);
}
protected void assertFileInZip(byte[] zip, String path, byte[] expectedContent) throws Exception {
</configuration>
</execution>
</executions>
- <dependencies>
- <dependency>
- <groupId>org.onap.vfc.nfvo.driver.vnfm.svnfm.nokiav2</groupId>
- <artifactId>generatortools</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>