public VmJobVirtualMachineOutcome(final AsyncJob job, final long vmId) { super(VirtualMachine.class, job, VmJobCheckInterval.value(), new Predicate() { @Override public boolean checkCondition() { AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, job.getId()); assert (jobVo != null); if (jobVo == null || jobVo.getStatus() != JobInfo.Status.IN_PROGRESS) return true; return false; } }, AsyncJob.Topics.JOB_STATE); }
@Override public Long getLBPreferredHostCheckInterval(final Long clusterId) { return IndirectAgentLBCheckInterval.valueIn(clusterId); }
@Override public String getEncryptionIV() { String value = EncryptionIV.value(); if (value == null) { _configDao.getValueAndInitIfNotExist(EncryptionIV.key(), EncryptionIV.category(), getBase64EncodedRandomKey(128), EncryptionIV.description()); } return EncryptionIV.value(); }
public ConfigurationVO(String component, ConfigKey<?> key) { this(key.category(), "DEFAULT", component, key.key(), key.defaultValue(), key.description()); defaultValue = key.defaultValue(); dynamic = key.isDynamic(); scope = key.scope() != null ? key.scope().toString() : null; }
public ScopedConfigStorage findScopedConfigStorage(ConfigKey<?> config) { for (ScopedConfigStorage storage : _scopedStorages) { if (storage.getScope() == config.scope()) { return storage; } } throw new CloudRuntimeException("Unable to find config storage for this scope: " + config.scope() + " for " + config.key()); }
private boolean saveNewRootCAKeypair() { try { LOG.debug("Generating root CA public/private keys"); final KeyPair keyPair = CertUtils.generateRandomKeyPair(2 * CAManager.CertKeySize.value()); if (!configDao.update(rootCAPublicKey.key(), rootCAPublicKey.category(), CertUtils.publicKeyToPem(keyPair.getPublic()))) { LOG.error("Failed to save RootCA public key"); } if (!configDao.update(rootCAPrivateKey.key(), rootCAPrivateKey.category(), CertUtils.privateKeyToPem(keyPair.getPrivate()))) { LOG.error("Failed to save RootCA private key"); } } catch (final NoSuchProviderException | NoSuchAlgorithmException | IOException e) { LOG.error("Failed to generate/save RootCA private/public keys due to exception:", e); } return loadRootCAKeyPair(); }
@Override public boolean checkRouterVersion(final VirtualRouter router) { if (!VirtualNetworkApplianceManagerImpl.routerVersionCheckEnabled.value()) { // Router version check is disabled. return true; } if (router.getTemplateVersion() == null) { return false; } final long dcid = router.getDataCenterId(); String routerVersion = CloudStackVersion.trimRouterVersion(router.getTemplateVersion()); return CloudStackVersion.compare(routerVersion, NetworkOrchestrationService.MinVRVersion.valueIn(dcid)) >= 0; }
private void overProvisioningFactorsForValidation() { overprovisioningFactorsForValidation = new HashSet<String>(); overprovisioningFactorsForValidation.add(CapacityManager.MemOverprovisioningFactor.key()); overprovisioningFactorsForValidation.add(CapacityManager.CpuOverprovisioningFactor.key()); overprovisioningFactorsForValidation.add(CapacityManager.StorageOverprovisioningFactor.key()); }
@Override public List<String> getManagementServerList(final Long hostId, final Long dcId, final List<Long> orderedHostIdList) { final String msServerAddresses = ApiServiceConfiguration.ManagementServerAddresses.value(); if (Strings.isNullOrEmpty(msServerAddresses)) { throw new CloudRuntimeException(String.format("No management server addresses are defined in '%s' setting", ApiServiceConfiguration.ManagementServerAddresses.key())); } List<Long> hostIdList = orderedHostIdList; if (hostIdList == null) { hostIdList = getOrderedHostIdList(dcId); } final org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm algorithm = getAgentMSLBAlgorithm(); final List<String> msList = Arrays.asList(msServerAddresses.replace(" ", "").split(",")); return algorithm.sort(msList, hostIdList, hostId); }
@Override public List<ConfigurationVO> getConfigListByScope(String scope, Long resourceId) { // Getting the list of parameters defined at the scope Set<ConfigKey<?>> configList = _configDepot.getConfigListByScope(scope); List<ConfigurationVO> configVOList = new ArrayList<ConfigurationVO>(); for (ConfigKey<?> param : configList) { ConfigurationVO configVo = _configDao.findByName(param.toString()); configVo.setValue(_configDepot.get(param.toString()).valueIn(resourceId).toString()); configVOList.add(configVo); } return configVOList; }
public T value() { if (_value == null || isDynamic()) { ConfigurationVO vo = s_depot != null ? s_depot.global().findById(key()) : null; final String value = (vo != null && vo.getValue() != null) ? vo.getValue() : defaultValue(); _value = ((value == null) ? (T)defaultValue() : valueOf(value)); } return _value; }
protected void populateConfiguration(Date date, Configurable configurable) { if (_configured.contains(configurable)) return; s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); for (ConfigKey<?> key : configurable.getConfigKeys()) { Pair<String, ConfigKey<?>> previous = _allKeys.get(key.key()); if (previous != null && !previous.first().equals(configurable.getConfigComponentName())) { throw new CloudRuntimeException("Configurable " + configurable.getConfigComponentName() + " is adding a key that has been added before by " + previous.first() + ": " + key.toString()); } _allKeys.put(key.key(), new Pair<String, ConfigKey<?>>(configurable.getConfigComponentName(), key)); createOrupdateConfigObject(date, configurable.getConfigComponentName(), key, null); if ((key.scope() != null) && (key.scope() != ConfigKey.Scope.Global)) { Set<ConfigKey<?>> currentConfigs = _scopeLevelConfigsMap.get(key.scope()); currentConfigs.add(key); } } _configured.add(configurable); }
private boolean saveNewRootCACertificate() { if (caKeyPair == null) { throw new CloudRuntimeException("Cannot issue self-signed root CA certificate as CA keypair is not initialized"); } try { LOG.debug("Generating root CA certificate"); final X509Certificate rootCaCertificate = CertUtils.generateV3Certificate( null, caKeyPair, caKeyPair.getPublic(), rootCAIssuerDN.value(), CAManager.CertSignatureAlgorithm.value(), getCaValidityDays(), null, null); if (!configDao.update(rootCACertificate.key(), rootCACertificate.category(), CertUtils.x509CertificateToPem(rootCaCertificate))) { LOG.error("Failed to update RootCA public/x509 certificate"); } } catch (final CertificateException | NoSuchAlgorithmException | NoSuchProviderException | SignatureException | InvalidKeyException | OperatorCreationException | IOException e) { LOG.error("Failed to generate RootCA certificate from private/public keys due to exception:", e); return false; } return loadRootCACertificate(); }
private void checkCommandAvailable(final User user, final String commandName, final InetAddress remoteAddress) throws PermissionDeniedException { if (user == null) { throw new PermissionDeniedException("User is null for role based API access check for command" + commandName); } final Account account = accountMgr.getAccount(user.getAccountId()); final String accessAllowedCidrs = ApiServiceConfiguration.ApiAllowedSourceCidrList.valueIn(account.getId()).replaceAll("\\s",""); final Boolean apiSourceCidrChecksEnabled = ApiServiceConfiguration.ApiSourceCidrChecksEnabled.value(); if (apiSourceCidrChecksEnabled) { s_logger.debug("CIDRs from which account '" + account.toString() + "' is allowed to perform API calls: " + accessAllowedCidrs); if (!NetUtils.isIpInCidrList(remoteAddress, accessAllowedCidrs.split(","))) { s_logger.warn("Request by account '" + account.toString() + "' was denied since " + remoteAddress + " does not match " + accessAllowedCidrs); throw new PermissionDeniedException("Calls for domain '" + account.getAccountName() + "' are not allowed from ip address '" + remoteAddress.getHostAddress()); } } for (final APIChecker apiChecker : apiAccessCheckers) { apiChecker.checkAccess(user, commandName); } }
@Override public void onPublishMessage(final String senderAddress, String subject, Object args) { final String globalSettingUpdated = (String) args; if (Strings.isNullOrEmpty(globalSettingUpdated)) { return; } if (globalSettingUpdated.equals(ApiServiceConfiguration.ManagementServerAddresses.key()) || globalSettingUpdated.equals(IndirectAgentLBAlgorithm.key())) { propagateMSListToAgents(); } } });
private void createOrupdateConfigObject(Date date, String componentName, ConfigKey<?> key, String value) { ConfigurationVO vo = _configDao.findById(key.key()); if (vo == null) { vo = new ConfigurationVO(componentName, key); vo.setUpdated(date); if (value != null) { vo.setValue(value); } _configDao.persist(vo); } else { if (vo.isDynamic() != key.isDynamic() || !ObjectUtils.equals(vo.getDescription(), key.description()) || !ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue()) || !ObjectUtils.equals(vo.getScope(), key.scope().toString()) || !ObjectUtils.equals(vo.getComponent(), componentName)) { vo.setDynamic(key.isDynamic()); vo.setDescription(key.description()); vo.setDefaultValue(key.defaultValue()); vo.setScope(key.scope().toString()); vo.setComponent(componentName); vo.setUpdated(date); _configDao.persist(vo); } } }
@Override public Long getDelay() { return CABackgroundJobDelay.value() * 1000L; } }
public static float getCpuOverprovisioningFactor(long clusterId) { float opFactor = CapacityManager.CpuOverprovisioningFactor.valueIn(clusterId); return opFactor; }
@Override public String getHashKey() { String value = HashKey.value(); if (value == null) { _configDao.getValueAndInitIfNotExist(HashKey.key(), HashKey.category(), getBase64EncodedRandomKey(128), HashKey.description()); } return HashKey.value(); }
/** * Retrieve global secondary storage NFS version default value * @return global default value */ protected Integer getGlobalDefaultNfsVersion(){ ConfigurationVO globalNfsVersion = configurationDao.findByName(CapacityManager.ImageStoreNFSVersion.key()); Preconditions.checkState(globalNfsVersion != null, "Unable to find global NFS version for version key " + CapacityManager.ImageStoreNFSVersion.key()); String value = globalNfsVersion.getValue(); return (value != null ? Integer.valueOf(value) : null); } /**