public static void save(VCenterForm vCenter) { if (!vCenter.canEditVcenter()) { VcenterRestRep dbVCenter = VCenterUtils.getVCenter(uri(vCenter.id)); if (dbVCenter != null) { vCenter.name = dbVCenter.getName(); } vCenter.save(false); flash.success(MessagesUtils.get(SAVED, vCenter.name)); list(); return; } vCenter.validate("vCenter"); if (Validation.hasErrors()) { edit(vCenter); } else { Boolean validateConnectionParam = params.get("validateConnection", Boolean.class); boolean validateConnection = validateConnectionParam != null ? validateConnectionParam.booleanValue() : false; vCenter.save(validateConnection); flash.success(MessagesUtils.get(SAVED, vCenter.name)); list(); } }
/** * Uploads a license file. This is restricted to admin users. * * @param licenseFile the license file. */ @Restrictions({ @Restrict({"SYSTEM_ADMIN", "SECURITY_ADMIN"}), @Restrict({"RESTRICTED_SYSTEM_ADMIN", "RESTRICTED_SECURITY_ADMIN"}) }) public static void upload(@Required File licenseFile) { if (Validation.hasErrors()) { params.flash(); Validation.keep(); license(); } try { String license = FileUtils.readFileToString(licenseFile); if (StringUtils.isBlank(license)) { Logger.error("License file is empty"); Validation.addError("setup.licenseFile", MessagesUtils.get("license.uploadFailed")); params.flash(); Validation.keep(); license(); } LicenseUtils.updateLicenseText(license); index(); } catch (IOException e) { Validation.addError("setup.licenseFile", MessagesUtils.get("license.uploadFailed")); Logger.error(e, "Failed to read license file"); Validation.keep(); license(); } }
@FlashException("list") public static void detachStorage(@As(",") String[] ids) { for (URI id : ResourceUtils.uris(ids)) { VCenterUtils.detachStorage(id); } flash.success(MessagesUtils.get(DETACH_STORAGE)); list(); }
@FlashException("list") public static void delete(@As(",") String[] ids, boolean detachStorage) { for (URI id : ResourceUtils.uris(ids)) { VCenterUtils.deactivateVCenter(id, detachStorage); } flash.success(MessagesUtils.get(DELETED)); list(); }
public void save(boolean validateConnection) { if (isNew()) { try { createVCenter(validateConnection); } catch (Exception e) { flash.error(MessagesUtils.get("validation.vcenter.messageAndError", e.getMessage())); Common.handleError(); } } else { try { updateVCenter(validateConnection); } catch (Exception e) { flash.error(MessagesUtils.get("validation.vcenter.messageAndError", e.getMessage())); Common.handleError(); } } }
@FlashException("list") @Restrictions({@Restrict("SECURITY_ADMIN")}) public static void edit(String id) { UserGroupRestRep userGroup = UserGroupUtils.getUserGroup(id); if (userGroup == null) { flash.error(MessagesUtils.get(UNKNOWN, id)); list(); } edit(new UserGroupForm(userGroup)); }
@FlashException(keep = true) public static void save(UserGroupForm userGroup) { userGroup.validate("userGroup"); if (Validation.hasErrors()) { Common.handleError(); } userGroup.save(); flash.success(MessagesUtils.get(SAVED, userGroup.name)); list(); }
public static void edit(String id) { VcenterRestRep dbVCenter = VCenterUtils.getVCenter(uri(id)); if (dbVCenter != null) { VCenterForm vCenter = new VCenterForm(dbVCenter); renderTenantOptions(); render(vCenter, dbVCenter); } else { flash.error(MessagesUtils.get(UNKNOWN, id)); list(); } }
public static void editVcenterDataCenter(String vcenterDataCenterId, String tenant) { VcenterDataCenterRestRep vcenterDataCenter = VcenterDataCenterUtils.getDataCenter(uri(vcenterDataCenterId)); if (vcenterDataCenter != null) { try { URI tenantId = NullColumnValueGetter.getNullURI(); if (StringUtils.isNotBlank(tenant)) { tenantId = uri(tenant); } VcenterDataCenterUtils.updateDataCenter(uri(vcenterDataCenterId), tenantId); list(); } catch (Exception e) { flash.error(MessagesUtils.get("validation.vcenter.messageAndError", e.getMessage())); Common.handleError(); } } else { flash.error(MessagesUtils.get(UNKNOWN, vcenterDataCenterId)); list(); } }
/** * Tests the SMTP settings from the initial setup form, rendering the result as JSON. * * @param setup the initial setup form. */ @Restrictions({ @Restrict({"SYSTEM_ADMIN", "SECURITY_ADMIN"}), @Restrict({"RESTRICTED_SYSTEM_ADMIN", "RESTRICTED_SECURITY_ADMIN"}) }) public static void testSmtpSettings(SetupForm setup) { setup.validateSmtp(); Validation.required("setup.smtpTo", setup.smtpTo); Validation.email("setup.smtpTo", setup.smtpTo); if (Validation.hasErrors()) { renderJSON(ValidationResponse.collectErrors()); } MailSettingsValidator.Settings settings = new MailSettingsValidator.Settings(); if (StringUtils.isNotEmpty(setup.nameservers) && !InetAddresses.isInetAddress(setup.smtpServer)) { Set<String> ips = Sets.newHashSet(setup.nameservers.split(",")); try { settings.server = DnsUtils.getHostIpAddress(ips, setup.smtpServer).getHostAddress(); } catch (ViPRException e) { renderJSON(ValidationResponse.invalid(e.getMessage())); } } else { settings.server = setup.smtpServer; } settings.port = ConfigProperties.getPort(setup.smtpPort, setup.smtpEnableTls); settings.username = setup.smtpUsername; settings.password = PasswordUtil.decryptedValue(setup.smtpPassword); settings.channel = StringUtils.equals("yes", setup.smtpEnableTls) ? "starttls" : "clear"; settings.authType = setup.smtpAuthType; settings.fromAddress = setup.smtpFrom; try { MailSettingsValidator.validate(settings, setup.smtpTo); } catch (RuntimeException e) { Logger.error(e, "Failed to send email"); Validation.addError(null, "setup.testEmail.failure", e.getMessage()); if (StringUtils.isEmpty(setup.nameservers)) { Validation.addError(null, "setup.smtpServer.invalidEmptyNameserver"); } } if (Validation.hasErrors()) { renderJSON(ValidationResponse.collectErrors()); } else { renderJSON(ValidationResponse.valid(MessagesUtils.get("setup.testEmail.success"))); } }
/** Displays the restarting screen. */ @Util private static void restarting() { flash.success(MessagesUtils.get("setup.waitStable.description")); Maintenance.maintenance(Common.reverseRoute(Setup.class, "index")); }