Skip to content

Commit

Permalink
Updated the NSE to use Open Baton libraries of release 6, updated the…
Browse files Browse the repository at this point in the history
… NSE to automatically create a service key if there is none provided
  • Loading branch information
Lars Grebe committed Sep 6, 2018
1 parent ba3157d commit 8d69dfc
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 258 deletions.
14 changes: 9 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ apply from: 'gradle/gradle/git.helpers.gradle'
apply from: 'gradle/gradle/command.line.helper.gradle'

project.ext {
//openbatonVersion = "5.0.0"
openbatonVersion = "5.2.1"

sdkVersion='6.0.0-RC2'
//exceptionVersion='5.2.1'
//monitoringVersion='5.2.1'
exceptionVersion='6.0.0-RC1'
monitoringVersion='6.0.0-RC1'

/**
* Application Related Version
Expand All @@ -74,9 +78,9 @@ dependencies {

compile("org.springframework.boot:spring-boot-starter-amqp")

compile 'org.openbaton:sdk:' + openbatonVersion
compile 'org.openbaton:exception:' + openbatonVersion
compile 'org.openbaton:monitoring:' + openbatonVersion
compile 'org.openbaton:sdk:' + sdkVersion
compile 'org.openbaton:exception:' + exceptionVersion
compile 'org.openbaton:monitoring:' + monitoringVersion

// compile ('org.apache.jclouds.driver:jclouds-slf4j:1.9.2')
// compile ('org.apache.jclouds.driver:jclouds-sshj:1.9.2')
Expand Down
374 changes: 141 additions & 233 deletions src/main/java/org/openbaton/nse/api/Api.java

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/main/java/org/openbaton/nse/properties/NfvoProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class NfvoProperties {
private String username;
private String password;
private Project project;
private SSL ssl;

public String getIp() {
return ip;
Expand Down Expand Up @@ -85,4 +86,29 @@ public void setName(String name) {
this.name = name;
}
}

public SSL getSsl() {
return ssl;
}

public void setSsl(SSL ssl) {
this.ssl = ssl;
}

public static class SSL {
boolean enabled;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public String toString() {
return "SSL{" + "enabled=" + enabled + '}';
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/org/openbaton/nse/properties/NseProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
* Created by maa on 01.02.16. modified by lgr on 20.07.17
*/
Expand Down
70 changes: 54 additions & 16 deletions src/main/java/org/openbaton/nse/utils/openbaton/OpenBatonTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance;
import org.openbaton.catalogue.nfvo.viminstances.OpenstackVimInstance;
import org.openbaton.catalogue.security.Project;
import org.openbaton.exceptions.NotFoundException;
import org.openbaton.catalogue.security.ServiceMetadata;
import org.openbaton.nse.properties.NfvoProperties;
import org.openbaton.nse.properties.NseProperties;
import org.openbaton.sdk.NFVORequestor;
import org.openbaton.sdk.NfvoRequestorBuilder;
import org.openbaton.sdk.api.exception.SDKException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,6 +36,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -47,29 +50,31 @@ public class OpenBatonTools {
@Autowired
private NfvoProperties nfvoProperties;

@SuppressWarnings("unused")
@Autowired
private NseProperties nseProperties;

private static Logger logger = LoggerFactory.getLogger(OpenBatonTools.class);

// This bean is actually used to instantiate

@Bean
@SuppressWarnings("unused")
public NFVORequestor getNFVORequestor()
throws SDKException, NotFoundException, FileNotFoundException {
public NFVORequestor getNFVORequestor() throws SDKException, FileNotFoundException {
if (!isNfvoStarted(nfvoProperties.getIp(), nfvoProperties.getPort())) {
logger.error("NFVO is not available");
System.exit(1);
}
NFVORequestor nfvoRequestor =
new NFVORequestor(
nfvoProperties.getUsername(),
nfvoProperties.getPassword(),
"*",
false,
nfvoProperties.getIp(),
nfvoProperties.getPort(),
"1");
NfvoRequestorBuilder.create()
.nfvoIp(nfvoProperties.getIp())
.nfvoPort(Integer.parseInt(nfvoProperties.getPort()))
.username(nfvoProperties.getUsername())
.password(nfvoProperties.getPassword())
.sslEnabled(nfvoProperties.getSsl().isEnabled())
.version("1")
.build();
logger.info("Starting the Open Baton Manager Bean");

try {
logger.info("Finding default project");
boolean found = false;
Expand All @@ -81,7 +86,7 @@ public NFVORequestor getNFVORequestor()
}
}
if (!found) {
throw new NotFoundException("Not found project " + nfvoProperties.getProject().getName());
logger.error("Not found project " + nfvoProperties.getProject().getName());
}
} catch (SDKException e) {
throw new SDKException(e);
Expand Down Expand Up @@ -158,9 +163,42 @@ public NFVORequestor getNFVORequestor(
String ip, String port, String project_id, String service_key) {
NFVORequestor requestor = null;
try {
// TODO : instead of false check for enabled SSL
// openbaton.getSsl().isEnabled()
requestor = new NFVORequestor("nse", project_id, ip, port, "1", false, service_key);
if (service_key.isEmpty()) {
logger.warn("No service key provided. Trying to self register as new service...");
if (nfvoProperties.getUsername().isEmpty() && nfvoProperties.getPassword().isEmpty()) {
logger.error("Not found user and/or password to self register as a new service...");
}
ServiceMetadata serviceMetadata = new ServiceMetadata();
serviceMetadata.setName("autoscaling-engine");
ArrayList<String> roles = new ArrayList<>();
roles.add("*");
NFVORequestor tmpNfvoRequestor =
NfvoRequestorBuilder.create()
.nfvoIp(nfvoProperties.getIp())
.nfvoPort(Integer.parseInt(nfvoProperties.getPort()))
.username(nfvoProperties.getUsername())
.password(nfvoProperties.getPassword())
.sslEnabled(nfvoProperties.getSsl().isEnabled())
.version("1")
.build();

String serviceKey = tmpNfvoRequestor.getServiceAgent().create("nse", roles);
logger.info("Received service key: " + serviceKey);
NseProperties.Service serv = new NseProperties.Service();
serv.setKey(serviceKey);
nseProperties.setService(serv);
}

requestor =
NfvoRequestorBuilder.create()
.nfvoIp(ip)
.nfvoPort(Integer.parseInt(port))
.serviceName("nse")
.serviceKey(service_key)
.projectId("*")
.sslEnabled(nfvoProperties.getSsl().isEnabled())
.version("1")
.build();
} catch (SDKException e) {
logger.error("Problem instantiating NFVORequestor for project " + project_id);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ nfvo.port=8080
nfvo.username=admin
nfvo.password=openbaton
nfvo.project.name=default
nfvo.ssl.enabled=false


##############################################
############## NSE properties ################
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/org/openbaton/nse/tests/RequestorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.openbaton.nse.tests;

import org.openbaton.catalogue.nfvo.VimInstance;
/*
import org.openbaton.catalogue.security.Project;
import org.openbaton.nse.properties.NfvoProperties;
import org.openbaton.sdk.NFVORequestor;
Expand All @@ -34,13 +34,17 @@
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
*/

/**
* Created by lgr on 10/4/17.
*/
public class RequestorTest {
public static void main(String[] args)
public static void main(String[] args) {}
/*
throws SDKException, FileNotFoundException, ClassNotFoundException {
NFVORequestor requestor =
new NFVORequestor("nse", "project_id", "127.0.0.1", "8080", "1", false, "service-key");
for (Project p : requestor.getProjectAgent().findAll()) {
Expand Down Expand Up @@ -151,4 +155,5 @@ private static OSClient getOSClient(VimInstance vimInstance) {
private static boolean isV3API(VimInstance vimInstance) {
return vimInstance.getAuthUrl().endsWith("/v3") || vimInstance.getAuthUrl().endsWith("/v3.0");
}
*/
}

0 comments on commit 8d69dfc

Please sign in to comment.