/** * It creates a tier. * * @throws EntityNotFoundException * @throws AlreadyExistsEntityException */ public Tier create(ClaudiaData claudiaData, String envName, Tier tier) throws InvalidEntityException, InfrastructureException, EntityNotFoundException, AlreadyExistsEntityException { log.info( "Create tier name " + tier.getName() + " image " + tier.getImage() + " flavour " + tier.getFlavour() + " initial_number_instances " + tier.getInitialNumberInstances() + " maximum_number_instances " + tier.getMaximumNumberInstances() + " minimum_number_instances " + tier.getMinimumNumberInstances() + " floatingIp " + tier.getFloatingip() + " keyPair " + tier.getKeypair() + " icon " + tier.getIcono() + " product releases " + tier.getProductReleases() + " vdc " + claudiaData.getVdc() + " networks " + tier.getNetworks()); if (exists(tier.getName(), tier.getVdc(), envName)) { return load(tier.getName(), claudiaData.getVdc(), envName); } else { // check if exist product or need sync with SDC existProductOrSyncWithSDC(claudiaData, tier); // createSecurityGroups(claudiaData, tier); createNetworks(tier); return tierInsertBD(tier, claudiaData); } }
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); } }
public EnvironmentInstance createInfrasctuctureEnvironmentInstance( EnvironmentInstance environmentInstance, Set<Tier> tiers, ClaudiaData claudiaData) throws InfrastructureException, InvalidEntityException, EntityNotFoundException, AlreadyExistsEntityException { // Deploy MVs log.info( "Creating infrastructure for environment instance " + environmentInstance.getBlueprintName()); for (Tier tier : tiers) { for (int numReplica = 1; numReplica <= tier.getInitialNumberInstances(); numReplica++) { // claudiaData.setVm(tier.getName()); log.info("Deploying tier instance for tier " + tier.getName() + " " + tier.getRegion()); Tier tierDB = tierManager.loadTierWithProductReleaseAndMetadata( tier.getName(), tier.getEnviromentName(), tier.getVdc()); TierInstance tierInstance = new TierInstance(); String name = generateVMName( environmentInstance.getBlueprintName(), tier.getName(), numReplica, claudiaData.getVdc()); tierInstance.setName(name); tierInstance.setNumberReplica(numReplica); tierInstance.setVdc(claudiaData.getVdc()); tierInstance.setStatus(Status.DEPLOYING); tierInstance.setTier(tierDB); VM vm = new VM(); String fqn = claudiaData.getOrg().replace("_", ".") + ".customers." + claudiaData.getVdc() + ".services." + claudiaData.getService() + ".vees." + tier.getName() + ".replicas." + numReplica; String hostname = generateVMName( claudiaData.getService(), tier.getName(), numReplica, claudiaData.getVdc()) .toLowerCase(); log.info("fqn " + fqn + " hostname " + hostname); vm.setFqn(fqn); vm.setHostname(hostname); tierInstance.setVM(vm); log.info("Deploy networks if required"); log.info("Deploying tier instance for tier " + tier.getName() + " " + tier.getRegion()); this.deployNetworks(claudiaData, tierInstance); log.info( "Number of networks " + tierInstance.getNetworkInstances().size() + " floatin ip " + tierInstance.getTier().getFloatingip()); log.info("Inserting in database "); tierInstance = insertTierInstanceBD( claudiaData, environmentInstance.getEnvironment().getName(), tierInstance); log.info( "Return: Number of networks " + tierInstance.getNetworkInstances().size() + " floating ip " + tierInstance.getTier().getFloatingip()); environmentInstance.addTierInstance(tierInstance); environmentInstanceDao.update(environmentInstance); try { tierInstanceManager.update( claudiaData, environmentInstance.getEnvironment().getName(), tierInstance); } catch (Exception e) { log.error("Error deploying a VM: " + e.getMessage()); environmentInstance.setStatus(Status.ERROR); throw new InfrastructureException(e.getMessage()); } log.info( "Tier instance name " + environmentInstance.getBlueprintName() + "-" + tier.getName() + "-" + numReplica); deployVM(claudiaData, tierInstance, numReplica, vm); tierInstance.setVM(vm); try { log.info("Inserting in database "); // tierInstance = insertTierInstanceBD(tierInstance); tierInstance.setStatus(Status.DEPLOYED); tierInstanceManager.update( claudiaData, environmentInstance.getEnvironment().getName(), tierInstance); } catch (EntityNotFoundException e) { log.info( "Entitiy NOt found: Tier " + tierInstance.getTier().getName() + " " + e.getMessage()); throw new InfrastructureException(e); } catch (InvalidEntityException e) { throw new InfrastructureException(e); } catch (AlreadyExistsEntityException e) { throw new InfrastructureException(e); } catch (Exception e) { throw new InfrastructureException(e); } } } return environmentInstance; }