/** * Invoked when a network creation is requested to check if the specified network can be created * and then creates the network * * @param network An instance of proposed new Neutron Network object. * @return A HTTP status code to the creation request. */ @Override public int canCreateNetwork(NeutronNetwork network) { if (network == null) { LOGGER.error("Network object can't be null.."); return HttpURLConnection.HTTP_BAD_REQUEST; } LOGGER.debug("Network object " + network); apiConnector = Activator.apiConnector; if (network.getNetworkUUID() == null || network.getNetworkName() == null || network.getNetworkUUID().equals("") || network.getNetworkName().equals("")) { LOGGER.error("Network UUID and Network Name can't be null/empty..."); return HttpURLConnection.HTTP_BAD_REQUEST; } try { return createNetwork(network); } catch (IOException ie) { LOGGER.error("IOException : " + ie); return HttpURLConnection.HTTP_INTERNAL_ERROR; } catch (Exception e) { LOGGER.error("Exception : " + e); return HttpURLConnection.HTTP_INTERNAL_ERROR; } }
/** * Invoked when a network update is requested to indicate if the specified network can be changed * using the specified delta. * * @param delta Updates to the network object using patch semantics. * @param original An instance of the Neutron Network object to be updated. * @return A HTTP status code to the update request. */ @Override public int canUpdateNetwork(NeutronNetwork deltaNetwork, NeutronNetwork originalNetwork) { VirtualNetwork virtualnetwork = new VirtualNetwork(); apiConnector = Activator.apiConnector; if (deltaNetwork == null || originalNetwork == null) { LOGGER.error("Neutron Networks can't be null.."); return HttpURLConnection.HTTP_BAD_REQUEST; } if (("").equals(deltaNetwork.getNetworkName())) { LOGGER.error("Neutron Networks name can't be empty.."); return HttpURLConnection.HTTP_BAD_REQUEST; } try { virtualnetwork = (VirtualNetwork) apiConnector.findById(VirtualNetwork.class, originalNetwork.getNetworkUUID()); } catch (IOException e) { LOGGER.error("Exception : " + e); return HttpURLConnection.HTTP_INTERNAL_ERROR; } if (virtualnetwork == null) { LOGGER.error("No network exists for the specified UUID..."); return HttpURLConnection.HTTP_FORBIDDEN; } else { try { return updateNetwork(deltaNetwork, virtualnetwork); } catch (IOException ie) { LOGGER.error("IOException: " + ie); return HttpURLConnection.HTTP_INTERNAL_ERROR; } catch (Exception e) { LOGGER.error("Exception: " + e); return HttpURLConnection.HTTP_INTERNAL_ERROR; } } }
/** * Invoked to map the NeutronNetwork object properties to the virtualNetwork object. * * @param neutronNetwork An instance of new Neutron Network object. * @param virtualNetwork An instance of new virtualNetwork object. * @return {@link VirtualNetwork} */ private VirtualNetwork mapNetworkProperties( NeutronNetwork neutronNetwork, VirtualNetwork virtualNetwork) { String networkUUID = neutronNetwork.getNetworkUUID(); String networkName = neutronNetwork.getNetworkName(); virtualNetwork.setName(networkName); virtualNetwork.setUuid(networkUUID); virtualNetwork.setDisplayName(networkName); return virtualNetwork; }
/** * Invoked to take action after a network has been updated. * * @param network An instance of modified Neutron Network object. */ @Override public void neutronNetworkUpdated(NeutronNetwork network) { try { VirtualNetwork virtualnetwork = new VirtualNetwork(); virtualnetwork = (VirtualNetwork) apiConnector.findById(VirtualNetwork.class, network.getNetworkUUID()); if (network.getNetworkName().equalsIgnoreCase(virtualnetwork.getDisplayName())) { LOGGER.info("Network updatation verified...."); } else { LOGGER.info("Network updatation failed...."); } } catch (Exception e) { LOGGER.error("Exception :" + e); } }
/** * Invoked to update the network * * @param delta_network An instance of Network. * @param virtualNetwork An instance of new virtualNetwork object. * @return A HTTP status code to the creation request. */ private int updateNetwork(NeutronNetwork deltaNetwork, VirtualNetwork virtualNetwork) throws IOException { String networkName = deltaNetwork.getNetworkName(); virtualNetwork.setName(networkName); virtualNetwork.setDisplayName(networkName); { boolean networkUpdate = apiConnector.update(virtualNetwork); if (!networkUpdate) { LOGGER.warn("Network Updation failed.."); return HttpURLConnection.HTTP_INTERNAL_ERROR; } LOGGER.info( "Network having UUID : " + virtualNetwork.getUuid() + " has been sucessfully updated..."); return HttpURLConnection.HTTP_OK; } }