protected AbstractMasterCheck(CConfiguration cConf) { this.cConf = cConf; this.systemServicesResourceKeys = MasterUtils.createSystemServicesResourceKeysSet(cConf); } }
private void ensureSecurityEnabled() throws FeatureDisabledException { if (!authenticationEnabled) { throw new FeatureDisabledException(FeatureDisabledException.Feature.AUTHENTICATION, FeatureDisabledException.CDAP_SITE, Constants.Security.ENABLED, "true"); } if (!authorizationEnabled) { throw new FeatureDisabledException(FeatureDisabledException.Feature.AUTHORIZATION, FeatureDisabledException.CDAP_SITE, Constants.Security.Authorization.ENABLED, "true"); } }
@Provider public class BadRequestExceptionMapper implements ExceptionMapper<BadRequestException> { public Response toResponse(BadRequestException ex) { return Response.status(404). entity(ex.getMessage()). type("text/plain"). build(); } }
private void checkLevels(int levels) throws BadRequestException { if (levels < 1) { throw new BadRequestException(String.format("Invalid levels (%d), should be greater than 0.", levels)); } }
private NamespaceId getValidatedNamespace(String namespaceStr) throws BadRequestException, MethodNotAllowedException { try { NamespaceId namespaceId = new NamespaceId(namespaceStr); if (namespaceId.equals(NamespaceId.SYSTEM)) { throw new MethodNotAllowedException( "Cannot perform profile methods on the system namespace. " + "Please use the top level profile endpoints to manage system profiles."); } return namespaceId; } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } }
private RunRecordMeta getRunRecordMeta(ProgramRunId programRunId) throws NotFoundException { RunRecordMeta runRecord = programStore.getRun(programRunId); if (runRecord == null) { throw new NotFoundException(programRunId); } return runRecord; } }
private NamespaceMeta fetchNamespaceMeta(NamespaceId namespaceId) throws Exception { NamespaceMeta ns = nsStore.get(namespaceId); if (ns == null) { throw new NamespaceNotFoundException(namespaceId); } return ns; }
/** * Checks if the scheduler started completely and is functional. * * @throws ServiceUnavailableException if the scheduler is not yet functional */ private void checkStarted() { if (!Uninterruptibles.awaitUninterruptibly(startedLatch, 0, TimeUnit.SECONDS)) { throw new ServiceUnavailableException("Core scheduler"); } }
private void verifyResponse(HttpResponse httpResponse) throws ConflictException { if (httpResponse.getResponseCode() == 409) { throw new ConflictException(httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } if (httpResponse.getResponseCode() != 200) { throw new HandlerException(HttpResponseStatus.valueOf(httpResponse.getResponseCode()), httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } } }
/** * Validate that the key length does not exceed the configured limit. */ private void validateLength(MetadataEntity metadataEntity, String keyword) throws InvalidMetadataException { // check for max char per value if (keyword.length() > maxCharacters) { throw new InvalidMetadataException( metadataEntity, "Metadata " + keyword + " exceeds maximum of " + maxCharacters + " characters."); } }
public FeatureDisabledException(Feature feature, String configName, String enableConfigKey, String enableConfigValue) { super(String.format("Feature '%s' is not enabled. Please set '%s' to '%s' in the '%s' to enable this feature.", feature.name().toLowerCase(), enableConfigKey, enableConfigValue, configName)); this.feature = feature; this.configName = configName; this.enableConfigKey = enableConfigKey; this.enableConfigValue = enableConfigValue; }
@Override public void ensureExists(ApplicationId appId) throws ApplicationNotFoundException { if (store.getApplication(appId) == null) { throw new ApplicationNotFoundException(appId); } } }
private NamespaceMeta getNamespaceMeta(FullHttpRequest request) throws BadRequestException { try { return parseBody(request, NamespaceMeta.class); } catch (JsonSyntaxException e) { throw new BadRequestException("Invalid json object provided in request body."); } } }
private NamespaceId getValidatedNamespace(String namespaceStr) throws BadRequestException, MethodNotAllowedException { try { NamespaceId namespaceId = new NamespaceId(namespaceStr); if (namespaceId.equals(NamespaceId.SYSTEM)) { throw new MethodNotAllowedException( "Cannot perform profile methods on the system namespace. " + "Please use the top level profile endpoints to manage system profiles."); } return namespaceId; } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } }
@Override public void ensureExists(ProgramRunId runId) throws NotFoundException { if (store.getRun(runId) == null) { throw new NotFoundException(runId); } } }
@Override public synchronized void updateProperties(NamespaceId namespaceId, NamespaceMeta namespaceMeta) throws Exception { if (namespaces.replace(namespaceId, namespaceMeta) == null) { throw new NamespaceNotFoundException(namespaceId); } } }
private void verifyResponse(HttpResponse httpResponse) throws ConflictException { if (httpResponse.getResponseCode() == 409) { throw new ConflictException(httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } if (httpResponse.getResponseCode() != 200) { throw new HandlerException(HttpResponseStatus.valueOf(httpResponse.getResponseCode()), httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } } }
private void ensureSecurityEnabled() throws FeatureDisabledException { if (!authenticationEnabled) { throw new FeatureDisabledException(FeatureDisabledException.Feature.AUTHENTICATION, FeatureDisabledException.CDAP_SITE, Constants.Security.ENABLED, "true"); } if (!authorizationEnabled) { throw new FeatureDisabledException(FeatureDisabledException.Feature.AUTHORIZATION, FeatureDisabledException.CDAP_SITE, Constants.Security.Authorization.ENABLED, "true"); } }
/** * Validate that the key is not reserved {@link MetadataDataset#TAGS_KEY}. */ private void validateTagReservedKey(MetadataEntity metadataEntity, String key) throws InvalidMetadataException { if (MetadataDataset.TAGS_KEY.equals(key.toLowerCase())) { throw new InvalidMetadataException(metadataEntity, "Could not set metadata with reserved key " + MetadataDataset.TAGS_KEY); } }
/** * Helper method to get the {@link LogLevelUpdater} for the program. */ private LogLevelUpdater getLogLevelUpdater(RuntimeInfo runtimeInfo) throws Exception { ProgramController programController = runtimeInfo.getController(); if (!(programController instanceof LogLevelUpdater)) { throw new BadRequestException("Update log levels at runtime is only supported in distributed mode"); } return ((LogLevelUpdater) programController); }