Skip to content

Commit

Permalink
Merge pull request #301 from openbaton/6.0
Browse files Browse the repository at this point in the history
6.0 features
  • Loading branch information
marcellom authored Aug 8, 2018
2 parents 8dddb71 + 82bfa7d commit bb557f6
Show file tree
Hide file tree
Showing 21 changed files with 1,076 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,9 @@
import org.openbaton.catalogue.mano.record.VNFCInstance;
import org.openbaton.catalogue.mano.record.VNFRecordDependency;
import org.openbaton.catalogue.mano.record.VirtualNetworkFunctionRecord;
import org.openbaton.catalogue.nfvo.Configuration;
import org.openbaton.catalogue.nfvo.DependencyParameters;
import org.openbaton.catalogue.nfvo.HistoryLifecycleEvent;
import org.openbaton.catalogue.nfvo.VNFCDependencyParameters;
import org.openbaton.catalogue.nfvo.*;
import org.openbaton.catalogue.nfvo.messages.Interfaces.NFVMessage;
import org.openbaton.exceptions.AlreadyExistingException;
import org.openbaton.exceptions.BadFormatException;
import org.openbaton.exceptions.BadRequestException;
import org.openbaton.exceptions.MissingParameterException;
import org.openbaton.exceptions.NotFoundException;
import org.openbaton.exceptions.PluginException;
import org.openbaton.exceptions.QuotaExceededException;
import org.openbaton.exceptions.VimDriverException;
import org.openbaton.exceptions.VimException;
import org.openbaton.exceptions.WrongStatusException;
import org.openbaton.exceptions.*;
import org.openbaton.nfvo.api.model.DependencyObject;
import org.openbaton.nfvo.core.interfaces.NetworkServiceRecordManagement;
import org.slf4j.Logger;
Expand Down Expand Up @@ -90,7 +78,7 @@ public class RestNetworkServiceRecord {
@ApiOperation(
value = "Deploying a Network Service Record from a JSON NSD",
notes =
"The NSD is passed in the Request Body as a json and the other needed parameters are passed as json in the bodyJson object"
"The NSD to be deployed is passed in the Request Body as a json, along with any other needed parameters."
)
@RequestMapping(
method = RequestMethod.POST,
Expand Down Expand Up @@ -202,6 +190,41 @@ public NetworkServiceRecord create(
id, projectId, keys, vduVimInstances, configurations, monitoringIp);
}

@RequestMapping(
value = "{nsrId}/vnfd/{vnfdId}",
method = RequestMethod.PUT,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.CREATED)
public NetworkServiceRecord scaleOut(
@PathVariable("nsrId") String nsrId,
@PathVariable("vnfdId") String vnfdId,
@RequestHeader(value = "project-id") String projectId,
@RequestBody(required = false) JsonObject jsonObject)
throws NotFoundException, MissingParameterException, BadRequestException,
InterruptedException, BadFormatException, ExecutionException, CyclicDependenciesException,
NetworkServiceIntegrityException {

log.debug("Json Body is" + jsonObject);
Type mapTypeConfigurations = new TypeToken<Map<String, Configuration>>() {}.getType();
Type mapTypeVduVimInstances = new TypeToken<Map<String, Set<String>>>() {}.getType();

String monitoringIp = null;
if (jsonObject.has("monitoringIp")) {
monitoringIp = jsonObject.get("monitoringIp").getAsString();
}

return networkServiceRecordManagement.scaleOutNsr(
nsrId,
vnfdId,
projectId,
gson.fromJson(jsonObject.getAsJsonArray("keys"), List.class),
gson.fromJson(jsonObject.getAsJsonObject("vduVimInstances"), mapTypeVduVimInstances),
gson.fromJson(jsonObject.get("configurations"), mapTypeConfigurations),
monitoringIp);
}

/**
* This operation is used to remove a Network Service Record
*
Expand All @@ -227,7 +250,8 @@ public void delete(
*/
@ApiOperation(
value = "Resume a failed Network Service Record",
notes = "The id in the URL specifies the Network Service Record that will be resumed"
notes =
"Resumes a NSR that failed while executing a script in a VNFR. The id in the URL specifies the Network Service Record that will be resumed."
)
@RequestMapping(value = "{id}/resume", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand All @@ -237,6 +261,42 @@ public void resume(
networkServiceRecordManagement.resume(id, projectId);
}

/**
* This operation is used to execute a script (or a command) on a specific VNF record during
* runtime
*
* @param idNsr : the id of Network Service Record
* @param idVnfr : the id of Virtual Network Function Record
* @throws NotFoundException
*/
@ApiOperation(
value = "Execute a script (or a command) on a specific VNF record of a specific NS record",
notes =
"Executes a script inside the given VNFR. The id of NSR and the id of the VNFR are specified in the URL"
)
@RequestMapping(value = "{idNsr}/vnfrecords/{idVnfr}/execute-script", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void executeScript(
@PathVariable("idNsr") String idNsr,
@PathVariable("idVnfr") String idVnfr,
@RequestHeader(value = "project-id") String projectId,
@RequestBody String scriptContent)
throws InterruptedException, ExecutionException, NotFoundException, BadFormatException {

VirtualNetworkFunctionRecord vnfr =
networkServiceRecordManagement.getVirtualNetworkFunctionRecord(idNsr, idVnfr, projectId);

// TODO: generate randomly script name
String scriptName = "ob_runtime_script";
Script script = new Script();
script.setName(scriptName);
script.setPayload(scriptContent.getBytes());

log.info("Executing script: " + script + " on VNFR: " + vnfr.getName());
log.info("Script content:\n----------\n" + scriptContent + "\n----------\n");
networkServiceRecordManagement.executeScript(idNsr, idVnfr, projectId, script);
}

/**
* Removes multiple Network Service Descriptor from the NSDescriptors repository
*
Expand Down Expand Up @@ -308,7 +368,7 @@ public NetworkServiceRecord findById(
@ApiOperation(
value = "Updating a Network Service Record",
notes =
"PUT request with the updated Network Service Record as JSON content in the request body and the id in the URL belongs to the NSR that shall be updated"
"The id in the URL belongs to the NSR that should be updated. The updated Network Service Record is passed as JSON content in the request body."
)
@RequestMapping(
value = "{id}",
Expand Down Expand Up @@ -760,25 +820,60 @@ public VirtualNetworkFunctionRecord postVNFR(

@ApiOperation(
value = "Update a Virtual Network Function Record in a NSR",
notes = "Specify the ids of the VNFR and NSR which will be updated"
notes = "Specify the ids of the parent NSR and of the VNFR which will be updated"
)
@RequestMapping(value = "{idNsr}/vnfrecords/{idVnfr}/update", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.ACCEPTED)
public void updateVnfr(
@PathVariable("idNsr") String idNsr,
@PathVariable("idVnfr") String idVnfr,
@RequestHeader(value = "project-id") String projectId)
throws NotFoundException, BadFormatException, ExecutionException, InterruptedException {
NetworkServiceRecord nsr = networkServiceRecordManagement.query(idNsr, projectId);
VirtualNetworkFunctionRecord vnfRecord =
networkServiceRecordManagement.getVirtualNetworkFunctionRecord(idNsr, idVnfr, projectId);
nsr.getVnfr().add(vnfRecord);

log.info("Executing UPDATE for VNFR: " + vnfRecord.getName());
networkServiceRecordManagement.updateVnfr(idNsr, idVnfr, projectId);
}

@ApiOperation(
value = "Upgrade a Virtual Network Function Record in a NSR",
notes = "Specify the ids of the parent NSR and of the VNFR which will be upgraded"
)
@RequestMapping(
value = "{idNsr}/vnfrecords/{idVnf}",
method = RequestMethod.PUT,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
value = "{idNsr}/vnfrecords/{idVnfr}/upgrade",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.ACCEPTED)
public VirtualNetworkFunctionRecord updateVNF(
@RequestBody @Valid VirtualNetworkFunctionRecord vnfRecord,
public void upgradeVnfr(
@PathVariable("idNsr") String idNsr,
@PathVariable("idVnf") String idVnf,
@RequestHeader(value = "project-id") String projectId)
throws NotFoundException {
@PathVariable("idVnfr") String idVnfr,
@RequestHeader(value = "project-id") String projectId,
@RequestBody @Valid JsonObject body)
throws NotFoundException, BadFormatException, BadRequestException, ExecutionException,
InterruptedException, IOException, VimException, PluginException {
NetworkServiceRecord nsr = networkServiceRecordManagement.query(idNsr, projectId);
VirtualNetworkFunctionRecord vnfRecord =
networkServiceRecordManagement.getVirtualNetworkFunctionRecord(idNsr, idVnfr, projectId);
nsr.getVnfr().add(vnfRecord);
networkServiceRecordManagement.update(nsr, idNsr, projectId);
return vnfRecord;

String upgradeRequestEntityKey = "vnfdId";

if (!body.has(upgradeRequestEntityKey)
|| !body.getAsJsonPrimitive(upgradeRequestEntityKey).isString())
throw new BadRequestException(
"The passed JSON is not correct. It should include a string field named: "
+ upgradeRequestEntityKey);

//String vnfPackageId = body.getAsJsonPrimitive("vnfPackageId").getAsString();
String upgradeVnfdId = body.getAsJsonPrimitive(upgradeRequestEntityKey).getAsString();

log.info("Executing UPGRADE for VNFR: " + vnfRecord.getName());

networkServiceRecordManagement.upgradeVnfr(idNsr, idVnfr, projectId, upgradeVnfdId);
}

@ApiOperation(
Expand Down Expand Up @@ -814,7 +909,10 @@ public void restartVNFR(
* @param id : the ID of NSR
* @return the list of VNFDependency objects of the NSR
*/
@ApiOperation(value = "Retrieve the VNF Dependencies of a NSR", notes = "")
@ApiOperation(
value = "Retrieve the VNF Dependencies of a NSR",
notes = "Retrieves the VNF Dependencies of the NSR, the id of which is specified in the URL"
)
@RequestMapping(
value = "{id}/vnfdependencies",
method = RequestMethod.GET,
Expand Down Expand Up @@ -929,7 +1027,7 @@ public VNFRecordDependency postVNFDependency(

@ApiOperation(
value = "Updates a VNF Dependency in an NSR",
notes = "Updates a VNF Dependency based on the if of the VNF it concerns"
notes = "Updates a VNF Dependency based on the id of the VNF it concerns"
)
@RequestMapping(
value = "{id}/vnfdependencies/{id_vnfd}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ public enum Action {
START,
STOP,
LOG_REQUEST,
RESUME
RESUME,
EXECUTE
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openbaton.catalogue.nfvo;

/** Created by lto on 18/05/15. */
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
Expand Down Expand Up @@ -46,6 +47,13 @@ public String toString() {
+ super.toString();
}

public Configuration() {}

public Configuration(String name) {
this.name = name;
this.configurationParameters = new HashSet<>();
}

public Set<ConfigurationParameter> getConfigurationParameters() {
return configurationParameters;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2016 Open Baton (http://www.openbaton.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.openbaton.catalogue.nfvo.messages;

import org.openbaton.catalogue.mano.record.VirtualNetworkFunctionRecord;
import org.openbaton.catalogue.nfvo.Action;
import org.openbaton.catalogue.nfvo.Script;
import org.openbaton.catalogue.nfvo.messages.Interfaces.OrVnfmMessage;

public class OrVnfmExecuteScriptMessage extends OrVnfmMessage {

private Script script;
private VirtualNetworkFunctionRecord vnfr;

public OrVnfmExecuteScriptMessage() {
this.action = Action.EXECUTE;
}

public Script getScript() {
return script;
}

public void setScript(Script script) {
this.script = script;
}

public void setVnfr(VirtualNetworkFunctionRecord vnfr) {
this.vnfr = vnfr;
}

public VirtualNetworkFunctionRecord getVnfr() {
return vnfr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,4 @@ public class RabbitConfiguration {
public static final String EXCHANGE_NAME_OPENBATON = "openbaton-exchange";
public static final String EXCHANGE_TYPE_OPENBATON = "topic";
public static final String EXCHANGE_DURABLE_OPENBATON = "true";

// /**
// * Extension of Spring-AMQP's {@link ConditionalRejectingErrorHandler.DefaultExceptionStrategy}.
// * It regards a {@link JsonSyntaxException}, which may appear while demarshalling a message from a
// * queue, as fatal and drops it. Otherwise the message would be sent back to the queue resulting
// * in an infinite loop.
// */
// private class HandleJsonSyntaxExceptionStrategy implements FatalExceptionStrategy {
//
// private Logger log = LoggerFactory.getLogger(this.getClass());
//
// @Override
// public boolean isFatal(Throwable t) {
// if (t instanceof ListenerExecutionFailedException
// && (t.getCause() instanceof MessageConversionException
// || t.getCause() instanceof JsonSyntaxException)) {
// log.error(
// "Fatal message conversion error; message rejected; "
// + "it will be dropped or routed to a dead letter exchange, if so configured: "
// + ((ListenerExecutionFailedException) t).getFailedMessage(),
// t);
// return true;
// }
// return false;
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import org.openbaton.catalogue.nfvo.Action;
import org.openbaton.catalogue.nfvo.messages.*;
import org.openbaton.catalogue.nfvo.messages.Interfaces.NFVMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmErrorMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmGenericMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmGrantLifecycleOperationMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmHealVNFRequestMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmInstantiateMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmLogMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmScalingMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmStartStopMessage;
import org.openbaton.catalogue.nfvo.messages.OrVnfmUpdateMessage;
import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -74,6 +66,9 @@ public NFVMessage deserialize(JsonElement json, Type typeOfT, JsonDeserializatio
case "LOG_REQUEST":
result = gson.fromJson(json, OrVnfmLogMessage.class);
break;
case "EXECUTE":
result = gson.fromJson(json, OrVnfmExecuteScriptMessage.class);
break;
default:
result = gson.fromJson(json, OrVnfmGenericMessage.class);
break;
Expand Down
Loading

0 comments on commit bb557f6

Please sign in to comment.