List of usage examples for org.apache.commons.lang BooleanUtils isNotTrue
public static boolean isNotTrue(Boolean bool)
Checks if a Boolean
value is not true
, handling null
by returning true
.
BooleanUtils.isNotTrue(Boolean.TRUE) = false BooleanUtils.isNotTrue(Boolean.FALSE) = true BooleanUtils.isNotTrue(null) = true
From source file:jp.primecloud.auto.api.lb.CreateLoadBalancer.java
/** * * ??/*from w ww . j a v a 2s. c o m*/ * * @param userName ?? * @param farmNo ? * @param loadBalancerName ?? * @param platformNo ? * @param loadBalancerType ?(aws or ultramonkey) * @param componentNo ??? * @param comment * * @return CreateLoadBalancerResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public CreateLoadBalancerResponse createLoadBalancer(@QueryParam(PARAM_NAME_USER) String userName, @QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_LOAD_BALANCER_NAME) String loadBalancerName, @QueryParam(PARAM_NAME_PLATFORM_NO) String platformNo, @QueryParam(PARAM_NAME_LOAD_BALANCER_TYPE) String loadBalancerType, @QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo, @QueryParam(PARAM_NAME_COMMENT) String comment, @QueryParam(PARAM_NAME_IS_INTERNAL) String isInternal) { CreateLoadBalancerResponse response = new CreateLoadBalancerResponse(); try { User user = userDao.readByUsername(userName); // ? // Key(??) ApiValidate.validateUser(userName); // FarmNo ApiValidate.validateFarmNo(farmNo); // LoadBalancerName ApiValidate.validateLoadBalancerName(loadBalancerName); // PlatformNo ApiValidate.validatePlatformNo(platformNo); Platform platform = platformDao.read(Long.parseLong(platformNo)); if (platform == null) { //???? throw new AutoApplicationException("EAPI-100000", "Platform", PARAM_NAME_PLATFORM_NO, platformNo); } if (!platformService.isUseablePlatforms(user.getUserNo(), platform) || BooleanUtils.isNotTrue(platform.getSelectable())) { //????? or ???? throw new AutoApplicationException("EAPI-000020", "Platform", PARAM_NAME_PLATFORM_NO, platformNo); } // LoadBalancerType ApiValidate.validateLoadBalancerType(loadBalancerType); PlatformAws platformAws = platformAwsDao.read(Long.parseLong(platformNo)); if (LB_TYPE_ELB.equals(loadBalancerType) && (PLATFORM_TYPE_AWS.equals(platform.getPlatformType()) == false || platformAws.getEuca())) { //loadBalancerType=ELB?=EC2?? //EC2?? ELB(Elastic Load Balancing)?? throw new AutoApplicationException("EAPI-000015", platform.getPlatformNo(), loadBalancerType); } // ComponentNo ApiValidate.validateComponentNo(componentNo); // Comment ApiValidate.validateComment(comment); // isInternal boolean internal = false; if (isInternal != null) { ApiValidate.validateIsInternal(isInternal); internal = Boolean.parseBoolean(isInternal); } if (!LB_TYPE_ELB.equals(loadBalancerType) || !platformAws.getVpc()) { if (BooleanUtils.isTrue(internal)) { // ELB ???VPC?????? throw new AutoApplicationException("EAPI -100041", loadBalancerName); } } // ??? Component component = componentDao.read(Long.parseLong(componentNo)); if (component == null) { // ?????? throw new AutoApplicationException("EAPI-100000", "Component", PARAM_NAME_COMPONENT_NO, componentNo); } if (BooleanUtils.isFalse(component.getFarmNo().equals(Long.parseLong(farmNo)))) { //??????? throw new AutoApplicationException("EAPI-100022", "Component", farmNo, PARAM_NAME_COMPONENT_NO, componentNo); } // ?? Long newLoadBalancerNo = null; if (LB_TYPE_ELB.equals(loadBalancerType)) { //AWS ELB(Elastic Load Balancing) newLoadBalancerNo = loadBalancerService.createAwsLoadBalancer(Long.parseLong(farmNo), loadBalancerName, comment, Long.parseLong(platformNo), Long.parseLong(componentNo), internal); } else if (LB_TYPE_ULTRA_MONKEY.equals(loadBalancerType)) { //ultraMonkey newLoadBalancerNo = loadBalancerService.createUltraMonkeyLoadBalancer(Long.parseLong(farmNo), loadBalancerName, comment, Long.parseLong(platformNo), Long.parseLong(componentNo)); } else if (LB_TYPE_CLOUDSTACK.equals(loadBalancerType)) { //cloudstack newLoadBalancerNo = loadBalancerService.createCloudstackLoadBalancer(Long.parseLong(farmNo), loadBalancerName, comment, Long.parseLong(platformNo), Long.parseLong(componentNo)); } response.setLoadBalancerNo(newLoadBalancerNo); response.setSuccess(true); } catch (Throwable e) { String message = ""; if (e instanceof AutoException || e instanceof AutoApplicationException) { message = e.getMessage(); } else { message = MessageUtils.getMessage("EAPI-000000"); } log.error(message, e); response.setMessage(message); response.setSuccess(false); } return response; }
From source file:jp.primecloud.auto.api.component.DescribeComponent.java
/** * * ?/*from w ww .j a v a 2s .c o m*/ * * @param farmNo ? * @param componentNo ??? * * @return DescribeComponentResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DescribeComponentResponse describeComponent(@QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo) { DescribeComponentResponse response = new DescribeComponentResponse(); try { // ? // FarmNo ApiValidate.validateFarmNo(farmNo); // ComponentNo ApiValidate.validateComponentNo(componentNo); // ??? Component component = componentDao.read(Long.parseLong(componentNo)); if (component == null || BooleanUtils.isTrue(component.getLoadBalancer())) { // ?????? ??? ??? throw new AutoApplicationException("EAPI-100000", "Component", PARAM_NAME_COMPONENT_NO, componentNo); } if (component.getFarmNo().equals(Long.parseLong(farmNo)) == false) { //??????? throw new AutoApplicationException("EAPI-100022", "Component", farmNo, PARAM_NAME_COMPONENT_NO, componentNo); } //?? response = new DescribeComponentResponse(component); List<ComponentInstance> componentInstances = componentInstanceDao .readByComponentNo(Long.parseLong(componentNo)); if (componentInstances.isEmpty() == false) { // Collections.sort(componentInstances, Comparators.COMPARATOR_COMPONENT_INSTANCE); for (ComponentInstance componentInstance : componentInstances) { // ????????? if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) { ComponentInstanceStatus status = ComponentInstanceStatus .fromStatus(componentInstance.getStatus()); if (status == ComponentInstanceStatus.STOPPED) { continue; } } //?? response.addInstance(new ComponentInstanceResponse(componentInstance)); } } response.setSuccess(true); } catch (Throwable e) { String message = ""; if (e instanceof AutoException || e instanceof AutoApplicationException) { message = e.getMessage(); } else { message = MessageUtils.getMessage("EAPI-000000"); } log.error(message, e); response.setMessage(message); response.setSuccess(false); } return response; }
From source file:jp.primecloud.auto.api.instance.CreateInstance.java
/** * * ??//from w w w . j av a 2 s . c om * * @param userName ?? * @param farmNo ? * @param platformNo ? * @param imageNo ? * @param instanceName ?? * @param instanceType * @param comment * * @return CreateInstanceResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public CreateInstanceResponse createInstance(@QueryParam(PARAM_NAME_USER) String userName, @QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_PLATFORM_NO) String platformNo, @QueryParam(PARAM_NAME_IMAGE_NO) String imageNo, @QueryParam(PARAM_NAME_INSTANCE_NAME) String instanceName, @QueryParam(PARAM_NAME_INSTANCE_TYPE) String instanceType, @QueryParam(PARAM_NAME_COMMENT) String comment) { CreateInstanceResponse response = new CreateInstanceResponse(); try { // ? // Key(??) ApiValidate.validateUser(userName); User user = userDao.readByUsername(userName); // FarmNo ApiValidate.validateFarmNo(farmNo); // PlatformNo ApiValidate.validatePlatformNo(platformNo); //? Platform platform = platformDao.read(Long.parseLong(platformNo)); if (platform == null) { //???? throw new AutoApplicationException("EAPI-100000", "Platform", PARAM_NAME_PLATFORM_NO, platformNo); } if (!platformService.isUseablePlatforms(user.getUserNo(), platform) || BooleanUtils.isNotTrue(platform.getSelectable())) { //????? or ???? throw new AutoApplicationException("EAPI-000020", "Platform", PARAM_NAME_PLATFORM_NO, platformNo); } // ImageNo ApiValidate.validateImageNo(imageNo); Image image = imageDao.read(Long.parseLong(imageNo)); if (image == null || !image.getPlatformNo().equals(platform.getPlatformNo())) { //???? or ????? throw new AutoApplicationException("EAPI-100000", "Image", PARAM_NAME_IMAGE_NO, imageNo); } if (BooleanUtils.isNotTrue(image.getSelectable())) { //??? throw new AutoApplicationException("EAPI-000020", "Image", PARAM_NAME_IMAGE_NO, imageNo); } // InstanceName ApiValidate.validateInstanceName(instanceName); // InstanceType ApiValidate.validateInstanceType(instanceType, false); List<String> instanceTypes = getInstanceTypes(platform, image); if (StringUtils.isEmpty(instanceType)) { instanceType = instanceTypes.get(0); } else { if (!instanceTypes.contains(instanceType)) { // ????????? throw new AutoApplicationException("EAPI-000011", imageNo, instanceType); } } // Comment ApiValidate.validateComment(comment); // ??Iaas()??()? Long newInstanceNo = null; // TODO CLOUD BRANCHING if (PLATFORM_TYPE_AWS.equals(platform.getPlatformType()) || PLATFORM_TYPE_CLOUDSTACK.equals(platform.getPlatformType()) || PLATFORM_TYPE_VCLOUD.equals(platform.getPlatformType()) || PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType()) || PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) { // AWS or Eucalyptus or Cloudstack or VCloud or Openstack or Azure newInstanceNo = instanceService.createIaasInstance(Long.parseLong(farmNo), instanceName, image.getPlatformNo(), comment, image.getImageNo(), instanceType); } else if (PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())) { // VMware newInstanceNo = instanceService.createVmwareInstance(Long.parseLong(farmNo), instanceName, image.getPlatformNo(), comment, image.getImageNo(), instanceType); } else if (PLATFORM_TYPE_NIFTY.equals(platform.getPlatformType())) { // Nifty newInstanceNo = instanceService.createNiftyInstance(Long.parseLong(farmNo), instanceName, image.getPlatformNo(), comment, image.getImageNo(), instanceType); } response.setInstanceNo(newInstanceNo); response.setSuccess(true); } catch (Throwable e) { String message = ""; if (e instanceof AutoException || e instanceof AutoApplicationException) { message = e.getMessage(); } else { message = MessageUtils.getMessage("EAPI-000000"); } log.error(message, e); response.setMessage(message); response.setSuccess(false); } return response; }
From source file:jp.primecloud.auto.api.component.ListComponent.java
/** * * ? ?????// www . j a v a 2 s .c o m * * @param farmNo ? * * @return ListComponentResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public ListComponentResponse listComponent(@QueryParam(PARAM_NAME_FARM_NO) String farmNo) { ListComponentResponse response = new ListComponentResponse(); try { // ? // FarmNo ApiValidate.validateFarmNo(farmNo); // ? Farm farm = farmDao.read(Long.parseLong(farmNo)); if (farm == null) { // ???? throw new AutoApplicationException("EAPI-100000", "Farm", PARAM_NAME_FARM_NO, farmNo); } // ??? List<Component> components = componentDao.readByFarmNo(Long.valueOf(farmNo)); if (components.isEmpty() == false) { // Collections.sort(components, Comparators.COMPARATOR_COMPONENT); } for (Component component : components) { if (BooleanUtils.isTrue(component.getLoadBalancer())) { //?????? continue; } //?? ComponentResponse componentResponse = new ComponentResponse(component); //??? List<ComponentInstance> componentInstances = componentInstanceDao .readByComponentNo(component.getComponentNo()); if (componentInstances.isEmpty() == false) { // Collections.sort(componentInstances, Comparators.COMPARATOR_COMPONENT_INSTANCE); Integer instanceCount = 0; for (ComponentInstance componentInstance : componentInstances) { // ????????? if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) { ComponentInstanceStatus status = ComponentInstanceStatus .fromStatus(componentInstance.getStatus()); if (status == ComponentInstanceStatus.STOPPED) { continue; } } instanceCount++; } // componentResponse.setInstanceCount(instanceCount); } //?? LoadBalancer loadBalancer = null; List<LoadBalancer> loadBalancers = loadBalancerDao.readByComponentNo(component.getComponentNo()); if (loadBalancers.isEmpty() == false) { // Collections.sort(loadBalancers, Comparators.COMPARATOR_LOAD_BALANCER); //???1? loadBalancer = loadBalancers.get(0); //??? componentResponse.setLoadBalancerName(loadBalancer.getLoadBalancerName()); } response.addComponents(componentResponse); } response.setSuccess(true); } catch (Throwable e) { String message = ""; if (e instanceof AutoException || e instanceof AutoApplicationException) { message = e.getMessage(); } else { message = MessageUtils.getMessage("EAPI-000000"); } log.error(message, e); response.setMessage(message); response.setSuccess(false); } return response; }
From source file:jp.primecloud.auto.process.nifty.NiftyInstanceProcess.java
public void stopInstance(NiftyProcessClient niftyProcessClient, Long instanceNo) { NiftyInstance niftyInstance = niftyInstanceDao.read(instanceNo); // ID?????/* w w w. j a va 2s . co m*/ if (StringUtils.isEmpty(niftyInstance.getInstanceId())) { return; } // ?? stop(niftyProcessClient, instanceNo); // ?????????? niftyInstance = niftyInstanceDao.read(instanceNo); if (BooleanUtils.isNotTrue(niftyInstance.getInitialized())) { terminate(niftyProcessClient, instanceNo); } }
From source file:com.wineaccess.winepermit.WinePermitHelper.java
/** * @param winePermitViewPO/*from w w w . j a v a 2 s .co m*/ * @return */ public static Map<String, Object> generateViewPermitResponse(WinePermitViewPO winePermitViewPO) { response = new FailureResponse(); Map<String, Object> outputViewPermit = new HashMap<String, Object>(); Long wineId = Long.parseLong(winePermitViewPO.getProductId()); final ProductItemModel productModel = ProductItemRepository.getProductItemById(wineId); if (productModel == null) { response.addError( new WineaccessError(SystemErrorCode.PERMIT_WINE_ERROR, SystemErrorCode.PERMIT_WINE_ERROR_TEXT)); } else { WineModel wineModel = WineRepository.getWineById(productModel.getItemId()); if (wineModel == null) { response.addError(new WineaccessError(SystemErrorCode.PERMIT_WINE_ERROR, SystemErrorCode.PERMIT_WINE_ERROR_TEXT)); } else { WineryModel wineryModel = wineModel.getWineryId(); if (BooleanUtils.isNotTrue(wineModel.getSellInAltStates()) && BooleanUtils.isNotTrue(wineModel.getSellInMainStates()) && (BooleanUtils.isNotFalse(wineryModel.getSellInAltStates()) || BooleanUtils.isNotFalse(wineryModel.getSellInMainStates()))) { copyFulfilModelFromWinery(wineModel); copyPermitModelFromWinery(wineModel); createNoPermitData(wineModel); wineModel.setSellInAltStates(wineryModel.getSellInAltStates()); wineModel.setSellInMainStates(wineryModel.getSellInMainStates()); wineModel.setOptionSelectedAltstates(wineryModel.getOptionSelectedAltstates()); WineRepository.update(wineModel); } WinePermitDetailVO winePermitViewVO = new WinePermitDetailVO(); winePermitViewVO.setWineId(wineModel.getId()); winePermitViewVO.setIsSellInMainStates(wineModel.getSellInMainStates()); SellInAltStatesResultModel sellInAltStatesModel = new SellInAltStatesResultModel(); if (BooleanUtils.isTrue(wineModel.getSellInAltStates())) sellInAltStatesModel.setIsSelected(true); Integer optionSelected = wineModel.getOptionSelectedAltstates(); if (optionSelected != null && optionSelected.equals(0)) { sellInAltStatesModel.setIsOptionSelectedKachinaAlt(true); } if (optionSelected != null && optionSelected.equals(2)) { sellInAltStatesModel.setIsOptionSelectedNoPermit(true); } List<PermitModelResult> permitModelResultsList = new ArrayList<PermitModelResult>(); OptionSelectedAltStatesResult optionSelectedAltStates = new OptionSelectedAltStatesResult(); List<WineLicensePermitAltStates> wineLicensePermitAltStates = WinePermitRepository .findWineLicensePermitAltStates(wineId); for (WineLicensePermitAltStates permitModelFromDB : wineLicensePermitAltStates) { PermitModelResult permitModelResult = new PermitModelResult(); WinePermitModelWithMasterData winePermitModelWithMasterData = new WinePermitModelWithMasterData(); MasterDataModel masterDataModel = new MasterDataModel(); Long masterDataForPermit = permitModelFromDB.getWineryPermit().getId(); permitModelResult.setDtcPermitEndDate(permitModelFromDB.getDtcPermitEndDate()); permitModelResult.setDtcPermitStartDate(permitModelFromDB.getDtcPermitStartDate()); permitModelResult.setDtcPermitNumber(permitModelFromDB.getDtcPermitNumber()); permitModelResult.setIsSelected(permitModelFromDB.getIsSelected()); permitModelResult.setPermitDurationInMonths(permitModelFromDB.getDtcPermitDurationInMonths()); masterDataModel.setId(masterDataForPermit); masterDataModel.setMasterDataTypeName(EnumTypes.MasterDataTypeEnum.WineryLicencePermit.name()); masterDataModel.setMasterDataName(permitModelFromDB.getWineryPermit().getName()); winePermitModelWithMasterData.setMasterData(masterDataModel); permitModelResult.setWinePermit(winePermitModelWithMasterData); permitModelResultsList.add(permitModelResult); } optionSelectedAltStates.setPermit(permitModelResultsList); /*}*/ WineLicenseFullfillAltStates fulfilModelFromDB = WinePermitRepository .findFulfilModelByWineId(wineId); FulFillModel fulfiModel = new FulFillModel(); if (fulfilModelFromDB != null) { if (BooleanUtils.isTrue(fulfilModelFromDB.getWaWillNotFullFill())) { } fulfiModel.setIsSelected(BooleanUtils.toStringTrueFalse(fulfilModelFromDB.getIsSelected())); fulfiModel.setEscrowContract( BooleanUtils.toStringTrueFalse(fulfilModelFromDB.getEscrowContract())); fulfiModel.setWaPlatformContract( BooleanUtils.toStringTrueFalse(fulfilModelFromDB.getWaPlatformContract())); fulfiModel.setIsStorageContact( BooleanUtils.toStringTrueFalse(fulfilModelFromDB.getWineryStorageContract())); optionSelectedAltStates.setFulfillDirectlyNotWA(fulfilModelFromDB.getWaWillNotFullFill()); } optionSelectedAltStates.setFulfill(fulfiModel); /*WineLicenseFullfillAltStates wineFullfillAltStatesModel = WinePermitRepository.findFulfilModelByWineId(wineModel.getId()); if(wineFullfillAltStatesModel!=null) { } sellInAltStatesModel.setOptionSelectedAltStates(optionSelectedAltStates); } } wineFullfillAltStatesModel = WinePermitRepository.findFulfilModelByWineId(wineModel.getId()); if(wineFullfillAltStatesModel!=null) { }*/ Long mappedWineryId = wineModel.getMappedWineryWithPermit(); if (mappedWineryId != null) { CustomWineryModel customWineryModel = new CustomWineryModel(); if (WineryRepository.getWineryById(mappedWineryId) != null) { customWineryModel.setWineryId(mappedWineryId); customWineryModel .setWineryName(WineryRepository.getWineryById(mappedWineryId).getWineryName()); optionSelectedAltStates.setMappedWineryWithPermit(customWineryModel); } } sellInAltStatesModel.setOptionSelectedAltStates(optionSelectedAltStates); Integer optionSelect = wineModel.getOptionSelectedAltstates(); if (optionSelect != null) { if (0 == optionSelect) { sellInAltStatesModel.setIsOptionSelectedKachinaAlt(true); } } List<WineLicenseNoPermit> wineLicenseNoPermit = WinePermitRepository .findWineLicenseNoPermitAltStates(wineId); List<OptionSelectedNoPermitResult> optionSelectedNoPermitResult = new ArrayList<OptionSelectedNoPermitResult>(); for (WineLicenseNoPermit wineLicenseNoPermitList : wineLicenseNoPermit) { OptionSelectedNoPermitResult noPermitResult = new OptionSelectedNoPermitResult(); WinePermitModelWithMasterData winePermitModelWithMasterData = new WinePermitModelWithMasterData(); MasterDataModel masterDataModel = new MasterDataModel(); Long masterDataForNoPermit = wineLicenseNoPermitList.getWineNoPermit().getId(); noPermitResult.setPriceFiled(wineLicenseNoPermitList.getPriceFiled()); noPermitResult.setSc3TStatus(wineLicenseNoPermitList.getStatus()); noPermitResult.setIsSelected(wineLicenseNoPermitList.getIsSelected()); masterDataModel.setId(masterDataForNoPermit); masterDataModel .setMasterDataTypeName(EnumTypes.MasterDataTypeEnum.WineryLicenceNoPermit.name()); masterDataModel.setMasterDataName(wineLicenseNoPermitList.getWineNoPermit().getName()); winePermitModelWithMasterData.setMasterData(masterDataModel); noPermitResult.setWinePermit(winePermitModelWithMasterData); optionSelectedNoPermitResult.add(noPermitResult); } sellInAltStatesModel.setOptionSelectedNoPermit(optionSelectedNoPermitResult); winePermitViewVO.setSellInAltStates(sellInAltStatesModel); /*}*/ response = new com.wineaccess.response.SuccessResponse(winePermitViewVO, 200); } } outputViewPermit.put("FINAL-RESPONSE", response); return outputViewPermit; }
From source file:jp.primecloud.auto.process.vmware.VmwareDiskProcess.java
/** * TODO: /*from w w w.ja va2 s . co m*/ * * @param vmwareProcessClient * @param instanceNo * @param diskNo */ public void detachDisk(VmwareProcessClient vmwareProcessClient, Long instanceNo, Long diskNo) { VmwareDisk vmwareDisk = vmwareDiskDao.read(diskNo); if (BooleanUtils.isNotTrue(vmwareDisk.getAttached())) { // ????????? return; } VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo); // Component component = componentDao.read(vmwareDisk.getComponentNo()); Instance instance = instanceDao.read(instanceNo); Platform platform = platformDao.read(vmwareProcessClient.getPlatformNo()); processLogger.writeLogSupport(ProcessLogger.LOG_DEBUG, component, instance, "VmwareDiskDetach", new Object[] { platform.getPlatformName(), vmwareDisk.getFileName() }); // ? vmwareProcessClient.detachDisk(vmwareInstance.getMachineName(), vmwareDisk.getScsiId()); // processLogger.writeLogSupport(ProcessLogger.LOG_DEBUG, component, instance, "VmwareDiskDetachFinish", new Object[] { platform.getPlatformName(), vmwareDisk.getFileName() }); // vmwareDisk = vmwareDiskDao.read(diskNo); vmwareDisk.setAttached(false); vmwareDiskDao.update(vmwareDisk); }
From source file:jp.primecloud.auto.service.impl.ProcessServiceImpl.java
/** * {@inheritDoc}// w w w . j av a 2 s. c o m */ @Override public void startInstances(Long farmNo, List<Long> instanceNos, boolean startComponent) { // ?? List<Instance> instances = instanceDao.readInInstanceNos(instanceNos); boolean skipServer = false; for (Instance instance : instances) { Platform platform = platformDao.read(instance.getPlatformNo()); if (PCCConstant.PLATFORM_TYPE_AWS.equals(platform.getPlatformType())) { PlatformAws platformAws = platformAwsDao.read(instance.getPlatformNo()); AwsInstance awsInstance = awsInstanceDao.read(instance.getInstanceNo()); if (platformAws.getVpc() && StringUtils.isEmpty(awsInstance.getSubnetId())) { //EC2+VPC???????????? instanceNos.remove(instance.getInstanceNo()); continue; } } if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) { AzureInstance azureInstance = azureInstanceDao.read(instance.getInstanceNo()); if (StringUtils.isEmpty(azureInstance.getSubnetId())) { //??????????? instanceNos.remove(instance.getInstanceNo()); continue; } // ??????2???? if (StringUtils.isEmpty(azureInstance.getInstanceName()) && skipServer == true) { instanceNos.remove(instance.getInstanceNo()); continue; } // ??????1?? if (StringUtils.isEmpty(azureInstance.getInstanceName()) && skipServer == false) { skipServer = true; } } if (BooleanUtils.isNotTrue(instance.getEnabled())) { instance.setEnabled(true); instanceDao.update(instance); } } if (startComponent) { // ??????? List<ComponentInstance> componentInstances = componentInstanceDao.readInInstanceNos(instanceNos); for (ComponentInstance componentInstance : componentInstances) { if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) { // ???????? if (BooleanUtils.isTrue(componentInstance.getEnabled()) || BooleanUtils.isNotTrue(componentInstance.getConfigure())) { componentInstance.setEnabled(false); componentInstance.setConfigure(true); componentInstanceDao.update(componentInstance); } continue; } if (BooleanUtils.isNotTrue(componentInstance.getEnabled()) || BooleanUtils.isNotTrue(componentInstance.getConfigure())) { componentInstance.setEnabled(true); componentInstance.setConfigure(true); componentInstanceDao.update(componentInstance); } } } // ???? scheduleFarm(farmNo); }
From source file:jp.primecloud.auto.process.lb.ElasticLoadBalancerProcess.java
public void configure(Long loadBalancerNo) { LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo); if (log.isInfoEnabled()) { log.info(// www . j a v a 2s. c om MessageUtils.getMessage("IPROCESS-200230", loadBalancerNo, loadBalancer.getLoadBalancerName())); } //IaasGatewayWrapper? Farm farm = farmDao.read(loadBalancer.getFarmNo()); IaasGatewayWrapper gateway = iaasGatewayFactory.createIaasGateway(farm.getUserNo(), loadBalancer.getPlatformNo()); try { // ??????? if (BooleanUtils.isNotTrue(loadBalancer.getEnabled())) { elbZabbixHostProcess.stopTemplate(loadBalancerNo); } // ? gateway.configureLoadBalancer(loadBalancer.getLoadBalancerNo()); // ?????? if (BooleanUtils.isTrue(loadBalancer.getEnabled())) { elbZabbixHostProcess.startTemplate(loadBalancerNo); } } catch (RuntimeException e) { loadBalancer = loadBalancerDao.read(loadBalancerNo); // ? List<LoadBalancerListener> listeners = loadBalancerListenerDao.readByLoadBalancerNo(loadBalancerNo); for (LoadBalancerListener listener : listeners) { LoadBalancerListenerStatus status; if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(listener.getEnabled())) { status = LoadBalancerListenerStatus.WARNING; } else { status = LoadBalancerListenerStatus.STOPPED; } if (status != LoadBalancerListenerStatus.fromStatus(listener.getStatus()) || BooleanUtils.isTrue(listener.getConfigure())) { listener.setStatus(status.toString()); listener.setConfigure(false); loadBalancerListenerDao.update(listener); } } // ?? List<LoadBalancerInstance> lbInstances = loadBalancerInstanceDao.readByLoadBalancerNo(loadBalancerNo); List<Long> targetInstanceNos = new ArrayList<Long>(); for (LoadBalancerInstance lbInstance : lbInstances) { targetInstanceNos.add(lbInstance.getInstanceNo()); } List<Instance> targetInstances = instanceDao.readInInstanceNos(targetInstanceNos); Map<Long, Instance> targetInstanceMap = new HashMap<Long, Instance>(); for (Instance targetInstance : targetInstances) { targetInstanceMap.put(targetInstance.getInstanceNo(), targetInstance); } for (LoadBalancerInstance lbInstance : lbInstances) { LoadBalancerInstanceStatus status; Instance targetInstance = targetInstanceMap.get(lbInstance.getInstanceNo()); if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(lbInstance.getEnabled()) && BooleanUtils.isTrue(targetInstance.getEnabled())) { status = LoadBalancerInstanceStatus.WARNING; } else { status = LoadBalancerInstanceStatus.STOPPED; } if (status != LoadBalancerInstanceStatus.fromStatus(lbInstance.getStatus())) { lbInstance.setStatus(status.toString()); loadBalancerInstanceDao.update(lbInstance); } } throw e; } // ? List<LoadBalancerListener> listeners = loadBalancerListenerDao.readByLoadBalancerNo(loadBalancerNo); for (LoadBalancerListener listener : listeners) { LoadBalancerListenerStatus status; if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(listener.getEnabled())) { status = LoadBalancerListenerStatus.RUNNING; } else { status = LoadBalancerListenerStatus.STOPPED; } if (status != LoadBalancerListenerStatus.fromStatus(listener.getStatus()) || BooleanUtils.isTrue(listener.getConfigure())) { listener.setStatus(status.toString()); listener.setConfigure(false); loadBalancerListenerDao.update(listener); } } // ?? List<LoadBalancerInstance> lbInstances = loadBalancerInstanceDao.readByLoadBalancerNo(loadBalancerNo); List<Long> targetInstanceNos = new ArrayList<Long>(); for (LoadBalancerInstance lbInstance : lbInstances) { targetInstanceNos.add(lbInstance.getInstanceNo()); } List<Instance> targetInstances = instanceDao.readInInstanceNos(targetInstanceNos); Map<Long, Instance> targetInstanceMap = new HashMap<Long, Instance>(); for (Instance targetInstance : targetInstances) { targetInstanceMap.put(targetInstance.getInstanceNo(), targetInstance); } for (LoadBalancerInstance lbInstance : lbInstances) { LoadBalancerInstanceStatus status; Instance targetInstance = targetInstanceMap.get(lbInstance.getInstanceNo()); if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(lbInstance.getEnabled()) && BooleanUtils.isTrue(targetInstance.getEnabled())) { status = LoadBalancerInstanceStatus.RUNNING; } else { status = LoadBalancerInstanceStatus.STOPPED; } if (status != LoadBalancerInstanceStatus.fromStatus(lbInstance.getStatus())) { lbInstance.setStatus(status.toString()); loadBalancerInstanceDao.update(lbInstance); } } if (log.isInfoEnabled()) { log.info( MessageUtils.getMessage("IPROCESS-200231", loadBalancerNo, loadBalancer.getLoadBalancerName())); } }
From source file:jp.primecloud.auto.api.lb.DescribeLoadBalancer.java
/** * * ??//from w ww . java 2 s . c o m * * @param farmNo ? * @param loadBalancerNo ?? * * @return DescribeLoadBalancerResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DescribeLoadBalancerResponse describeLoadBalancer(@QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo) { DescribeLoadBalancerResponse response = new DescribeLoadBalancerResponse(); try { // ? // FarmNo ApiValidate.validateFarmNo(farmNo); // LoadBalancerNo ApiValidate.validateLoadBalancerNo(loadBalancerNo); // ?? LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo)); if (loadBalancer == null) { // ????? throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo); } if (BooleanUtils.isFalse(loadBalancer.getFarmNo().equals(Long.parseLong(farmNo)))) { //?????? throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo, PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo); } //? response = new DescribeLoadBalancerResponse(loadBalancer); //? List<LoadBalancerListener> listeners = loadBalancerListenerDao .readByLoadBalancerNo(Long.parseLong(loadBalancerNo)); if (listeners.isEmpty() == false) { // Collections.sort(listeners, Comparators.COMPARATOR_LOAD_BALANCER_LISTENER); } for (LoadBalancerListener listener : listeners) { // response.addListener(new LoadBalancerListenerResponse(listener)); } //?? LoadBalancerHealthCheck healthCheck = loadBalancerHealthCheckDao.read(Long.parseLong(loadBalancerNo)); if (healthCheck != null) { //? response.setHealthCheck(new LoadBalancerHealthCheckResponse(healthCheck)); } //??? List<ComponentInstance> componentInstances = componentInstanceDao .readByComponentNo(loadBalancer.getComponentNo()); if (componentInstances.isEmpty() == false) { // Collections.sort(componentInstances, Comparators.COMPARATOR_COMPONENT_INSTANCE); } for (ComponentInstance componentInstance : componentInstances) { // ????????? if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) { ComponentInstanceStatus status = ComponentInstanceStatus .fromStatus(componentInstance.getStatus()); if (status == ComponentInstanceStatus.STOPPED) { continue; } } //?? LoadBalancerInstance loadBalancerInstance = loadBalancerInstanceDao .read(Long.parseLong(loadBalancerNo), componentInstance.getInstanceNo()); LoadBalancerInstanceResponse loadBalancerInstanceResponse = new LoadBalancerInstanceResponse(); loadBalancerInstanceResponse.setInstanceNo(componentInstance.getInstanceNo()); if (loadBalancerInstance == null) { //?????????? loadBalancerInstanceResponse.setEnabled(false); loadBalancerInstanceResponse.setStatus(LoadBalancerInstanceStatus.STOPPED.toString()); } else { loadBalancerInstanceResponse.setEnabled(loadBalancerInstance.getEnabled()); loadBalancerInstanceResponse.setStatus(loadBalancerInstance.getStatus()); } //? response.addInstance(loadBalancerInstanceResponse); } //? AutoScalingConf autoScalingConf = autoScalingConfDao.read(Long.parseLong(loadBalancerNo)); if (autoScalingConf != null) { // response.setAutoScaling(new AutoScalingConfResponse(autoScalingConf)); } response.setSuccess(true); } catch (Throwable e) { String message = ""; if (e instanceof AutoException || e instanceof AutoApplicationException) { message = e.getMessage(); } else { message = MessageUtils.getMessage("EAPI-000000"); } log.error(message, e); response.setMessage(message); response.setSuccess(false); } return response; }