Skip to content

Commit

Permalink
Merge branch 'master' into image_repository
Browse files Browse the repository at this point in the history
  • Loading branch information
mpauls authored May 10, 2019
2 parents e455953 + 624a0ec commit 38c21bd
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,18 @@
import org.openbaton.exceptions.VimException;
import org.openbaton.nfvo.core.interfaces.ComponentManager;
import org.openbaton.nfvo.core.interfaces.VimManagement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/datacenters")
public class RestVimInstances {

// TODO add log prints
// private Logger log = LoggerFactory.getLogger(this.getClass());
private Logger log = LoggerFactory.getLogger(this.getClass());

@Autowired private VimManagement vimManagement;
@Autowired private ComponentManager componentManager;
Expand All @@ -74,6 +69,7 @@ public BaseVimInstance create(
@RequestHeader(value = "project-id") String projectId)
throws VimException, PluginException, IOException, BadRequestException, ExecutionException,
InterruptedException {
log.info("Adding vim instance: " + vimInstance);
return vimManagement.add(vimInstance, projectId).get();
}

Expand All @@ -90,6 +86,7 @@ public BaseVimInstance create(
public void delete(
@PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId)
throws NotFoundException, BadRequestException {
log.info("Deleting vim instance id: " + id);
vimManagement.delete(id, projectId);
}

Expand All @@ -111,6 +108,7 @@ public void delete(
public void multipleDelete(
@RequestBody @Valid List<String> ids, @RequestHeader(value = "project-id") String projectId)
throws NotFoundException, BadRequestException {
log.info("Deleting vim instance ids: " + ids);
for (String id : ids) vimManagement.delete(id, projectId);
}

Expand All @@ -131,12 +129,12 @@ public List<BaseVimInstance> findAll(
String[] tokenArray = token.split(" ");
if (tokenArray.length < 2) throw new BadFormatException("The passed token has a wrong format.");
token = tokenArray[1];
log.info("Retrieving all vim instances");
Iterable<BaseVimInstance> vimInstances = vimManagement.queryByProjectId(projectId);
if (!componentManager.isService(token))
for (BaseVimInstance vim : vimInstances) {
handlePrivateInfo(vim);
}

return (List<BaseVimInstance>) vimInstances;
}

Expand All @@ -155,6 +153,7 @@ public BaseVimInstance findById(
@RequestHeader(value = "project-id") String projectId,
@RequestHeader(value = "authorization") String token)
throws NotFoundException, BadFormatException {
log.info("Retrieving vim instance id: " + id);
BaseVimInstance vim = vimManagement.query(id, projectId);
if (vim == null) throw new NotFoundException("VIM Instance with ID " + id + " not found.");
String[] tokenArray = token.split(" ");
Expand All @@ -166,10 +165,26 @@ public BaseVimInstance findById(
return vim;
}

/**
* Returns the Datacenter selected by name
*
* @param name: The Datacenter's name
* @return Datacenter: The Datacenter requested
*/
@ApiOperation(
value = "Retrieve a Vim Instance by name",
notes = "Returns the Vim Instance JSON belonging to the name specified")
@GetMapping(value = "search/findByName")
public BaseVimInstance findByName(
@RequestParam String name, @RequestHeader(value = "project-id") String projectId)
throws NotFoundException {
return vimManagement.queryByProjectIdAndName(projectId, name);
}

/**
* This operation updates the Network Service Descriptor (NSD)
*
* @param new_vimInstance the new datacenter to be updated to
* @param newVimInstance the new datacenter to be updated to
* @param id the id of the old datacenter
* @return VimInstance the VimInstance updated
*/
Expand All @@ -184,12 +199,14 @@ public BaseVimInstance findById(
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public BaseVimInstance update(
@RequestBody @Valid BaseVimInstance new_vimInstance,
@RequestBody @Valid BaseVimInstance newVimInstance,
@PathVariable("id") String id,
@RequestHeader(value = "project-id") String projectId)
throws VimException, PluginException, IOException, BadRequestException, NotFoundException,
ExecutionException, InterruptedException {
return vimManagement.update(new_vimInstance, id, projectId).get();
log.info("Updating vim instance with id: " + id);
log.debug("New vim instance: " + newVimInstance);
return vimManagement.update(newVimInstance, id, projectId).get();
}

/**
Expand All @@ -206,6 +223,7 @@ public BaseVimInstance update(
public Set<? extends BaseNfvImage> getAllImages(
@PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId)
throws NotFoundException {
log.info("Retrieving images from vim instance id: " + id);
BaseVimInstance vimInstance = vimManagement.query(id, projectId);
if (vimInstance == null)
throw new NotFoundException("VIM Instance with ID " + id + " not found.");
Expand All @@ -229,6 +247,7 @@ public BaseNfvImage getImage(
@PathVariable("idImage") String idImage,
@RequestHeader(value = "project-id") String projectId)
throws EntityUnreachableException, NotFoundException {
log.info("Retrieving image " + idImage + " from vim instance id: " + idVim);
return vimManagement.queryImage(idVim, idImage, projectId);
}

Expand All @@ -250,6 +269,8 @@ public BaseNfvImage addImage(
@RequestHeader(value = "project-id") String projectId)
throws VimException, PluginException, EntityUnreachableException, IOException,
NotFoundException {
log.info("Adding image to vim instance id: " + id);
log.debug("Image to add: " + nfvImage);
return vimManagement.addImage(id, nfvImage, projectId);
}

Expand Down Expand Up @@ -291,6 +312,7 @@ public void deleteImage(
@RequestHeader(value = "project-id") String projectId)
throws VimException, PluginException, EntityUnreachableException, IOException,
NotFoundException {
log.info("Deleting image " + idImage + " from vim instance id: " + idVim);
vimManagement.deleteImage(idVim, idImage, projectId);
}

Expand All @@ -311,6 +333,7 @@ public BaseVimInstance refresh(
BaseVimInstance vimInstance = vimManagement.query(id, projectId);
if (vimInstance == null)
throw new NotFoundException("VIM Instance with ID " + id + " not found.");
log.info("Refreshing vim instance: " + id);
vimManagement.refresh(vimInstance, true).get();
return vimInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public NetworkServiceRecord create(
@RequestHeader(value = "project-id") String projectId,
@RequestBody(required = false) String bodyJson)
throws InterruptedException, ExecutionException, VimException, NotFoundException,
BadFormatException, PluginException, MissingParameterException, BadRequestException,
IOException, AlreadyExistingException {
BadFormatException, PluginException, BadRequestException, IOException,
AlreadyExistingException {

JsonObject jsonObject;
try {
Expand All @@ -116,7 +116,7 @@ public NetworkServiceRecord create(
}

/**
* @param id of the NSR
* @param id of the NSD
* @param projectId if of the project
* @param body the body json is: { "vduVimInstances":{ "vduName1":[ "viminstancename" ],
* "vduName2":[ "viminstancename2" ] }, "keys":[ "keyname1", "keyname2" ], "configurations":{
Expand All @@ -132,8 +132,6 @@ public NetworkServiceRecord create(
* @throws VimException
* @throws NotFoundException
* @throws BadFormatException
* @throws VimDriverException
* @throws QuotaExceededException
* @throws PluginException
*/
@ApiOperation(
Expand All @@ -151,8 +149,8 @@ public NetworkServiceRecord create(
@RequestHeader(value = "project-id") String projectId,
@RequestBody(required = false) JsonObject body)
throws InterruptedException, ExecutionException, VimException, NotFoundException,
BadFormatException, PluginException, MissingParameterException, BadRequestException,
IOException, AlreadyExistingException {
BadFormatException, PluginException, BadRequestException, IOException,
AlreadyExistingException {

String monitoringIp = null;
List keys = null;
Expand Down Expand Up @@ -444,10 +442,6 @@ public void deleteVNFRecord(
*
* @param ids: the id list of Virtual Network Function Records
* @throws NotFoundException
* @throws InterruptedException
* @throws ExecutionException
* @throws WrongStatusException
* @throws VimException
*/
@ApiOperation(
value = "Removing multiple Virtual Network Function Records",
Expand Down Expand Up @@ -616,8 +610,6 @@ public void stopVNFCInstance(
* @throws NotFoundException
* @throws BadFormatException
* @throws WrongStatusException
* @throws ExecutionException
* @throws InterruptedException
*/
@ApiOperation(
value = "Add a VNFC in standby",
Expand Down Expand Up @@ -1122,8 +1114,6 @@ public LinkedHashSet<HistoryLifecycleEvent> getHistory(
.getLifecycle_event_history();
}

// TODO The Rest of the classes

private PhysicalNetworkFunctionRecord findPNFD(
Collection<PhysicalNetworkFunctionRecord> listPNFR, String id_pnf) throws NotFoundException {
for (PhysicalNetworkFunctionRecord pRecord : listPNFR) {
Expand All @@ -1143,14 +1133,4 @@ private VNFRecordDependency findVNFD(
}
throw new NotFoundException("VNFD with id " + id_vnfd + " was not found");
}

private VirtualNetworkFunctionRecord findVNF(
Collection<VirtualNetworkFunctionRecord> listVNF, String id_vnf) throws NotFoundException {
for (VirtualNetworkFunctionRecord vnfRecord : listVNF) {
if (vnfRecord.getId().equals(id_vnf)) {
return vnfRecord;
}
}
throw new NotFoundException("VNFR with id " + id_vnf + " was not found");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,15 @@
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance;
import org.openbaton.catalogue.nfvo.viminstances.OpenstackVimInstance;
import org.openbaton.exceptions.AlreadyExistingException;
import org.openbaton.exceptions.BadFormatException;
import org.openbaton.exceptions.BadRequestException;
import org.openbaton.exceptions.NotFoundException;
Expand All @@ -62,17 +56,15 @@ public void init() {
}

@Test
public void findAllVimInstances()
throws NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
NoSuchPaddingException, IllegalBlockSizeException, BadFormatException {
public void findAllVimInstances() throws BadFormatException {
when(mock.queryByProjectId("pi")).thenReturn(new ArrayList<>());
assertEquals(mock.queryByProjectId("pi"), restVimInstances.findAll("pi", "Bearer token"));
}

@Test
public void createVimInstance()
throws VimException, PluginException, IOException, BadRequestException,
AlreadyExistingException, ExecutionException, InterruptedException {
throws VimException, PluginException, IOException, BadRequestException, ExecutionException,
InterruptedException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
Expand All @@ -89,9 +81,7 @@ public void createVimInstance()
}

@Test
public void findByIdVimInstance()
throws NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
NoSuchPaddingException, IllegalBlockSizeException, NotFoundException, BadFormatException {
public void findByIdVimInstance() throws NotFoundException, BadFormatException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
Expand All @@ -101,10 +91,21 @@ public void findByIdVimInstance()
assertEquals(datacenter, restVimInstances.findById(datacenter.getId(), "pi", "Bearer token"));
}

@Test
public void findByNameVimInstance() throws NotFoundException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
datacenter.setType("OpenStack");
datacenter.setName("datacenter_test");
when(mock.queryByProjectIdAndName(anyString(), anyString())).thenReturn(datacenter);
assertEquals(datacenter, restVimInstances.findByName(datacenter.getName(), "pi"));
}

@Test
public void updateVimInstance()
throws VimException, PluginException, IOException, BadRequestException,
AlreadyExistingException, NotFoundException, ExecutionException, InterruptedException {
throws VimException, PluginException, IOException, BadRequestException, NotFoundException,
ExecutionException, InterruptedException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public static void handlePrivateInfo(BaseVimInstance vim) {
}
}

public static String getVimNameWithoutAvailabilityZone(String vimName) {
if (vimName.contains(":")) return vimName.split(":")[0];
return vimName;
}

public static void updatePrivateInfo(BaseVimInstance vimNew, BaseVimInstance vimOld) {
if (vimNew
.getClass()
Expand Down
Loading

0 comments on commit 38c21bd

Please sign in to comment.