@Override public void unregister(VnfmManagerEndpoint endpoint) { Iterable<VnfmManagerEndpoint> vnfmManagerEndpoints = vnfmEndpointRepository.findAll(); for (VnfmManagerEndpoint vnfmManagerEndpoint : vnfmManagerEndpoints) { // TODO: decide whether the type or the endpoint (or both) is the unique identifier if (endpoint.getType().equals(vnfmManagerEndpoint.getType())) { log.info("Unregistered vnfm: " + endpoint.getType()); this.vnfmEndpointRepository.delete(vnfmManagerEndpoint.getId()); return; } } log.error("no VNFM found for endpoint: " + endpoint); } }
@Override public VnfmManagerEndpoint getVnfm(String endpoint) throws NotFoundException { log.trace("Looking for vnfmEndpoint endpoint: " + endpoint); for (VnfmManagerEndpoint vnfmManagerEndpoint : this.vnfmEndpointRepository.findAll()) { log.trace("" + vnfmManagerEndpoint); if (vnfmManagerEndpoint.getType().equals(endpoint)) { return vnfmManagerEndpoint; } } throw new NotFoundException("VnfManager of endpoint " + endpoint + " is not registered"); }
private void listVnfms() { String line = String.format("%20s%20s%20s", "Vnfm type", "active", "enable"); System.out.println(line); for (VnfmManagerEndpoint endpoint : vnfmEndpointRepository.findAll()) { System.out.println( String.format( "%20s%20s%20s", endpoint.getType(), endpoint.isActive(), endpoint.isEnabled())); } }
@Override public void addManagerEndpoint(String endpoint_json) { VnfmManagerEndpoint endpoint = gson.fromJson(endpoint_json, VnfmManagerEndpoint.class); if (endpoint.getEndpointType() == null) { endpoint.setEndpointType(EndpointType.RABBIT); } log.info("Registering endpoint of type: " + endpoint.getType()); try { this.register(endpoint); } catch (AlreadyExistingException e) { log.warn(e.getLocalizedMessage()); } }
public void checkEndpoint(String endpointName, Iterable<VnfmManagerEndpoint> endpoints) throws NotFoundException { boolean found = false; for (VnfmManagerEndpoint endpoint : endpoints) { log.debug("Check if VNFM is registered: " + endpoint.getType() + " == " + endpointName); if (endpoint.getType().equals(endpointName) && endpoint.isActive() && endpoint.isEnabled()) { found = true; break; } } if (!found) { throw new NotFoundException( "VNFManager with endpoint: " + endpointName + " is not registered, not enabled or not active."); } if (!found) { throw new NotFoundException("No VNFManagers were found"); } }
message.add("type", new JsonPrimitive(endpoint.getType())); message.add("action", new JsonPrimitive("register")); message.add("vnfmManagerEndpoint", gson.toJsonTree(endpoint, VnfmManagerEndpoint.class));
message.add("type", new JsonPrimitive(endpoint.getType())); message.add("action", new JsonPrimitive("register")); message.add("vnfmManagerEndpoint", gson.toJsonTree(endpoint, VnfmManagerEndpoint.class));
@Override public void register(VnfmManagerEndpoint endpoint) throws AlreadyExistingException { log.debug("Persisting: " + endpoint); for (VnfmManagerEndpoint endpointExisting : vnfmEndpointRepository.findAll()) { // TODO: decide whether the type or the endpoint (or both) is the unique identifier. strategy // here is different than in unregister function if (endpointExisting.getEndpoint().equals(endpoint.getEndpoint()) && endpointExisting.getType().equals(endpoint.getType()) && endpointExisting.getEndpointType().equals(endpoint.getEndpointType())) throw new AlreadyExistingException( "VnfmManagerEndpoint " + endpoint + " already exists in the DB"); } endpoint.setActive(true); this.vnfmEndpointRepository.save(endpoint); }
@Scheduled(initialDelay = 30000, fixedDelay = 20000) public void checkHeartBeat() { for (VnfmManagerEndpoint endpoint : vnfmEndpointRepository.findAll()) { if (endpoint.getEndpointType().ordinal() == EndpointType.RABBIT.ordinal()) { if (endpoint.isEnabled()) { try { if (!RabbitManager.getQueues( brokerIp.trim(), username, password, virtualHost, managementPort) .contains(endpoint.getEndpoint())) { if (endpoint.isActive()) { log.info("Set endpoint " + endpoint.getType() + " to unactive"); endpoint.setActive(false); vnfmEndpointRepository.save(endpoint); } } else { if (!endpoint.isActive()) { log.info("Set endpoint " + endpoint.getType() + " to active"); endpoint.setActive(true); vnfmEndpointRepository.save(endpoint); } } } catch (IOException ignored) { log.warn("Not able to list queues, probably " + brokerIp.trim() + " is not reachable."); } } } } } }
public void checkEndpoint( NetworkServiceDescriptor networkServiceDescriptor, Iterable<VnfmManagerEndpoint> endpoints) throws NotFoundException { // since the check for existence of VNFDs is done prior to this method call, we can assume that // at least one VNFD // exists if (networkServiceDescriptor.getVnfd().size() == 0) { throw new RuntimeException( "The NSD contains no VNFDs. This exception is not expected to be thrown at any time. If it is, you found a " + "bug."); } boolean found = false; for (VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor : networkServiceDescriptor.getVnfd()) { for (VnfmManagerEndpoint endpoint : endpoints) { if (endpoint.getType().equals(virtualNetworkFunctionDescriptor.getEndpoint()) && endpoint.isActive() && endpoint.isEnabled()) { found = true; break; } } if (!found) { throw new NotFoundException( "VNFManager with endpoint: " + virtualNetworkFunctionDescriptor.getEndpoint() + " is not registered or not enabled or not active."); } } }
if (!pingHost(url.getHost(), url.getPort(), 2)) { if (endpoint.isActive()) { log.info("Set endpoint " + endpoint.getType() + " to unactive"); endpoint.setActive(false); vnfmEndpointRepository.save(endpoint); log.info("Set endpoint " + endpoint.getType() + " to active"); endpoint.setActive(true); vnfmEndpointRepository.save(endpoint);