private void checkDates(Date startDate, Date endDate) { if (startDate.compareTo(endDate) > 0) { throw new UserFacingException(new IllegalArgumentException("Start must be less than or equal to end: " + startDate + " > " + endDate + " (" + startDate.getTime() + " > " + endDate.getTime() + ")")); } }
return ApiError.of(userFacing.getMessage()).asBadRequestResponseJson();
protected Exception newRE(String message) { return new UserFacingException(message); }
@SuppressWarnings("unchecked") private <T> T checkType(Object x, String description, Class<T> type) { if (type.isInstance(x)) return (T)x; throw new UserFacingException("Expected "+JavaClassNames.superSimpleClassName(type)+" for "+description+", not "+JavaClassNames.superSimpleClassName(x)); }
@Override public Void call() throws Exception { checkCanReadPassword(); System.out.print("Enter password: "); System.out.flush(); String password = readPassword(); if (Strings.isBlank(password)) { throw new UserFacingException("Password must not be blank; aborting"); } System.out.print("Re-enter password: "); System.out.flush(); String password2 = readPassword(); if (!password.equals(password2)) { throw new UserFacingException("Passwords did not match; aborting"); } String salt = Identifiers.makeRandomId(4); String sha256password = PasswordHasher.sha256(salt, new String(password)); System.out.println(); System.out.println("Please add the following to your brooklyn.properties:"); System.out.println(); System.out.println("brooklyn.webconsole.security.users="+user); System.out.println("brooklyn.webconsole.security.user."+user+".salt="+salt); System.out.println("brooklyn.webconsole.security.user."+user+".sha256="+sha256password); return null; }
result.services.add(Service.of((Map<String,Object>) service)); } else { throw new UserFacingException("Services list should have a map for each entry, not "+JavaClassNames.superSimpleClassName(service)); throw new UserFacingException("Services block should be a list, not "+JavaClassNames.superSimpleClassName(services)); result.artifacts.add(Artifact.of((Map<String,Object>) artifact)); } else { throw new UserFacingException("Artifacts list should contain map items, not "+JavaClassNames.superSimpleClassName(artifact)); throw new UserFacingException("Artifacts block should contain a list, not "+JavaClassNames.superSimpleClassName(artifacts));
protected void applyMatchers(Object deploymentPlanItem, AssemblyTemplateConstructor atc) { for (PdpMatcher matcher: getMatchers()) { if (matcher.accepts(deploymentPlanItem)) { // TODO first accepting is a crude way to do matching ... but good enough to start if (matcher.apply(deploymentPlanItem, atc)) return; } } throw new UserFacingException("Unable to match plan item: "+deploymentPlanItem); }
public void upload(Path zip) throws ParsingException, CSARVersionAlreadyExistsException { LOG.debug("Uploading type: " + zip); ParsingResult<Csar> types = archiveUploadService.upload(zip); if (ArchiveUploadService.hasError(types, ParsingErrorLevel.ERROR)) { throw new UserFacingException("Errors parsing types:\n" + Strings.join(types.getContext().getParsingErrors(), "\n ")); } }
String typeToLoad = strippedType.isPresent() ? strippedType.get() : type; if (osgiClassPrefixer.hasPrefix(typeToLoad)) { bundleProblems.put(osgiBundle, new UserFacingException("Bundle does not match prefix in type name '"+typeToLoad+"'")); continue;
public ParsingResult<Csar> uploadArchive(File zipFile, String callerReferenceName) { try { String nameCleaned = Strings.makeValidFilename(callerReferenceName); ParsingResult<Csar> result = archiveUploadService.upload(Paths.get(zipFile.toString())); if (ArchiveUploadService.hasError(result, null)) { LOG.debug("A4C parse notes for " + nameCleaned + ":\n " + Strings.join(result.getContext().getParsingErrors(), "\n ")); } if (ArchiveUploadService.hasError(result, ParsingErrorLevel.ERROR)) { // archive will not be installed in this case, so we should throw throw new UserFacingException("Could not parse " + callerReferenceName + " as TOSCA:\n " + Strings.join(result.getContext().getParsingErrors(), "\n ")); } return result; } catch (Exception e) { throw Exceptions.propagate("Error uploading archive " + callerReferenceName, e); } }
} catch (Exception e) { Exceptions.propagateIfFatal(e); throw new UserFacingException("Cannot resolve URL: "+uri, e);
if (rt.getKind()==RegisteredTypeKind.UNRESOLVED) { errors++; catInit.handleException(new UserFacingException("Unresolved type in catalog"), rt);
private Response launch(String yaml, EntitySpec<? extends Application> spec, Optional<String> entityId) { try { Application app = EntityManagementUtils.createUnstarted(mgmt(), spec, entityId); boolean isEntitled = Entitlements.isEntitled( mgmt().getEntitlementManager(), Entitlements.INVOKE_EFFECTOR, EntityAndItem.of(app, StringAndArgument.of(Startable.START.getName(), null))); if (!isEntitled) { throw WebResourceUtils.forbidden("User '%s' is not authorized to start application %s", Entitlements.getEntitlementContext().user(), spec.getType()); } CreationResult<Application,Void> result = EntityManagementUtils.start(app); waitForStart(app, Duration.millis(100)); log.info("Launched from YAML: " + yaml + " -> " + app + " (" + result.task() + ")"); URI ref = serviceAbsoluteUriBuilder(ui.getBaseUriBuilder(), ApplicationApi.class, "get").build(app.getApplicationId()); ResponseBuilder response = created(ref); if (result.task() != null) response.entity(TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(result.task())); return response.build(); } catch (ConstraintViolationException e) { throw new UserFacingException(e); } catch (Exception e) { throw Exceptions.propagate(e); } }
if (includePrecedingComments) { if (getEndOfPrevious() > getStartOfThis()) { throw new UserFacingException("YAML not in expected format; when scanning, previous end "+getEndOfPrevious()+" exceeds this start "+getStartOfThis());
public ParsingResult<Csar> parse(String plan) { ParsingResult<Csar> tp; PlanTypeChecker type = new PlanTypeChecker(plan); if (!type.isTosca) { if (type.csarLink == null) { throw new PlanNotRecognizedException("Does not look like TOSCA"); } tp = uploader.uploadArchive(new ResourceUtils(this).getResourceFromUrl(type.csarLink), "submitted-tosca-archive"); } else { tp = uploader.uploadSingleYaml(Streams.newInputStreamWithContents(plan), "submitted-tosca-plan"); } if (ArchiveUploadService.hasError(tp, ParsingErrorLevel.ERROR)) { throw new UserFacingException("Could not parse TOSCA plan: " + Strings.join(tp.getContext().getParsingErrors(), "\n ")); } return tp; } }