public void createNetworks(Tier tier) throws EntityNotFoundException, InvalidEntityException, AlreadyExistsEntityException { List<Network> networkToBeDeployed = new ArrayList<Network>(); for (Network network : tier.getNetworks()) { networkToBeDeployed.add(network); } for (Network network : networkToBeDeployed) { if (networkManager.exists(network.getNetworkName(), network.getVdc(), tier.getRegion())) { log.info("the network " + network.getNetworkName() + " already exists"); network = networkManager.load(network.getNetworkName(), network.getVdc(), tier.getRegion()); } else { network = networkManager.create(network); } tier.addNetwork(network); } }
public void updateTier(ClaudiaData data, Tier tierold, Tier tiernew) throws InvalidEntityException, EntityNotFoundException, AlreadyExistsEntityException { tierold.setFlavour(tiernew.getFlavour()); tierold.setFloatingip(tiernew.getFloatingip()); tierold.setIcono(tiernew.getIcono()); tierold.setImage(tiernew.getImage()); tierold.setInitialNumberInstances(tiernew.getInitialNumberInstances()); tierold.setKeypair(tiernew.getKeypair()); tierold.setMaximumNumberInstances(tiernew.getMaximumNumberInstances()); tierold.setMinimumNumberInstances(tiernew.getMinimumNumberInstances()); tierold.setRegion(tiernew.getRegion()); update(tierold); // Get networks to be delete Set<Network> nets = new HashSet<Network>(); for (Network net : tierold.getNetworks()) { nets.add(net); } // delete networks tierold.setNetworks(null); update(tierold); // adding networks for (Network net : tiernew.getNetworks()) { log.info("Creating new network " + net.getNetworkName()); try { net = networkManager.create(net); } catch (AlreadyExistsEntityException e) { net = networkManager.load(net.getNetworkName(), net.getVdc(), net.getRegion()); } tierold.addNetwork(net); update(tierold); } for (Network net : nets) { if (isAvailableToBeDeleted(net)) { networkManager.delete(net); } } tierold.setProductReleases(null); update(tierold); if (tiernew.getProductReleases() == null) return; for (ProductRelease productRelease : tiernew.getProductReleases()) { try { productRelease = productReleaseManager.load( productRelease.getProduct() + "-" + productRelease.getVersion(), data); } catch (EntityNotFoundException e) { log.error( "The new software " + productRelease.getProduct() + "-" + productRelease.getVersion() + " is not found"); } tierold.addProductRelease(productRelease); update(tierold); } }
/** * It insert the tier in the database. * * @param tier * @param data * @return * @throws InvalidEntityException * @throws InfrastructureException */ public Tier tierInsertBD(Tier tier, ClaudiaData data) throws InvalidEntityException, InfrastructureException { List<Network> networskout = new ArrayList(); try { return load(tier.getName(), tier.getVdc(), tier.getEnviromentName()); } catch (EntityNotFoundException e) { // tier.setVdc(data.getVdc()); // tier.setEnviromentName(data.getService()); List<ProductRelease> productReleases = new ArrayList(); if (tier.getProductReleases() != null && tier.getProductReleases().size() != 0) { for (ProductRelease p : tier.getProductReleases()) { productReleases.add(p); } } else { log.warn("There is not any product release associated to the tier " + tier.getName()); } for (Network p : tier.getNetworks()) { networskout.add(p); } try { tier.setProductReleases(null); tier.setNetworks(null); tier = tierDao.create(tier); } catch (Exception e2) { String errorMessage = "The Tier " + tier.getName() + " cannot be created " + e2.getMessage(); log.error(errorMessage); // restore(data, tier); throw new InvalidEntityException(errorMessage); } if (productReleases.size() != 0) { for (ProductRelease product : productReleases) { try { ProductRelease templateProduct = productReleaseManager.load(product.getProduct() + "-" + product.getVersion(), data); log.info( "Adding product release " + templateProduct.getProduct() + "-" + templateProduct.getVersion() + " to tier " + templateProduct.getName()); mergeAttributes(product, templateProduct); mergeMetadatas(product, templateProduct); tier.addProductRelease(templateProduct); tier = update(tier); } catch (Exception e2) { String errorMessage = "The ProductRelease Object " + product.getProduct() + "-" + product.getVersion() + " is " + "NOT present in Database"; log.error(errorMessage); throw new InvalidEntityException(e2); } } } } for (Network net : networskout) { try { net = networkManager.load(net.getNetworkName(), net.getVdc(), net.getRegion()); log.info("Adding network " + net.getNetworkName() + "-" + " to tier " + tier.getName()); tier.addNetwork(net); update(tier); } catch (Exception e2) { String errorMessage = "The Network Object " + net.getNetworkName() + " is " + "NOT present in Database"; log.error(errorMessage); throw new InvalidEntityException(e2); } } return tier; }