use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class InferenceResource method infer.
@POST
@Path("/models/{modelName: [a-zA-Z0-9]+}{version:(/versions/[0-9]+)?}{verb:((" + InferenceVerb.ANNOTATION + "))?}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Make inference")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB, Audience.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response infer(@ApiParam(value = "Name of the model to query", required = true) @PathParam("modelName") String modelName, @ApiParam(value = "Version of the model to query") @PathParam("version") String modelVersion, @ApiParam(value = "Type of query") @PathParam("verb") InferenceVerb verb, @Context SecurityContext sc, @Context HttpHeaders httpHeaders, String inferenceRequestJson) throws InferenceException, ApiKeyException {
Integer version = null;
if (!Strings.isNullOrEmpty(modelVersion)) {
version = Integer.valueOf(modelVersion.split("/")[2]);
}
Users user = jWTHelper.getUserPrincipal(sc);
String authHeader = httpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION).get(0);
String inferenceResult = inferenceController.infer(project, sc.getUserPrincipal().getName(), modelName, version, verb, inferenceRequestJson, authHeader);
return Response.ok().entity(inferenceResult).build();
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class DefaultJobConfigurationResource method getByType.
@ApiOperation(value = "Get the default job configuration by JobType", response = DefaultJobConfigurationDTO.class)
@GET
@Path("{type}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getByType(@PathParam("type") JobType jobType, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProjectException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.JOBCONFIG);
DefaultJobConfiguration defaultJobConfiguration = projectController.getProjectDefaultJobConfiguration(project, jobType);
if (defaultJobConfiguration == null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_DEFAULT_JOB_CONFIG_NOT_FOUND, Level.FINEST);
} else {
DefaultJobConfigurationDTO defaultJobConfigurationDTO = this.defaultJobConfigurationBuilder.build(uriInfo, resourceRequest, defaultJobConfiguration, jobType);
return Response.ok(defaultJobConfigurationDTO).build();
}
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class DefaultJobConfigurationResource method get.
@ApiOperation(value = "Get all the default job configurations", response = DefaultJobConfigurationDTO.class)
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@BeanParam Pagination pagination, @BeanParam DefaultJobConfigurationBeanParam defaultJobConfigurationBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProjectException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.JOBCONFIG);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setSort(defaultJobConfigurationBeanParam.getSortBySet());
resourceRequest.setFilter(defaultJobConfigurationBeanParam.getFilter());
DefaultJobConfigurationDTO defaultJobConfigurationDTO = this.defaultJobConfigurationBuilder.build(uriInfo, resourceRequest, this.project);
if (defaultJobConfigurationDTO == null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_DEFAULT_JOB_CONFIG_NOT_FOUND, Level.FINEST);
}
return Response.ok(defaultJobConfigurationDTO).build();
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class ProjectProvenanceResource method usage.
@GET
@Path("usage")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.PROJECT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Artifact usage", response = ProvArtifactUsageParentDTO.class)
public Response usage(@QueryParam("artifact_id") String artifactId, @QueryParam("endpoint_id") Integer endpointId, @QueryParam("artifact_type") DatasetAccessType accessType, @BeanParam ProvUsageBeanParams params, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProvenanceException, GenericException, DatasetException, MetadataException, SchematizedTagException {
Users user = jWTHelper.getUserPrincipal(sc);
if (artifactId == null) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "artifactId id cannot be null");
}
Project targetProject = project;
if (endpointId != null) {
targetProject = projectFacade.findById(endpointId).orElseThrow(() -> new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "target project not found"));
}
Dataset targetEndpoint;
if (accessType != null) {
try {
switch(accessType) {
case FEATUREGROUPS:
targetEndpoint = fsCtrl.getProjectFeaturestoreDataset(targetProject);
break;
case TRAININGDATASETS:
String tdName = project.getName() + "_" + Settings.ServiceDataset.TRAININGDATASETS.getName();
targetEndpoint = datasetCtrl.getByName(targetProject, tdName);
break;
case MODELS:
targetEndpoint = datasetCtrl.getByName(targetProject, Settings.HOPS_MODELS_DATASET);
break;
case EXPERIMENTS:
targetEndpoint = datasetCtrl.getByName(targetProject, Settings.HOPS_EXPERIMENTS_DATASET);
break;
default:
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "access type not supports:" + accessType);
}
} catch (FeaturestoreException | DatasetException e) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_STATE, Level.FINE, "cannot access the dataset of the artifact");
}
} else {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_STATE, Level.FINE, "access type not defined");
}
DatasetPath targetEndpointPath = datasetHelper.getTopLevelDatasetPath(project, targetEndpoint);
ProvArtifactUsageParentDTO status = usageBuilder.buildAccessible(uriInfo, user, targetEndpointPath, artifactId, params.getUsageType());
return Response.ok().entity(status).build();
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class EnvironmentResource method getAll.
@ApiOperation(value = "Get all python environments for this project", response = EnvironmentDTO.class)
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.PYTHON }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getAll(@BeanParam EnvironmentExpansionBeanParam expansions, @Context UriInfo uriInfo, @Context SecurityContext sc) throws PythonException, IOException, ServiceDiscoveryException {
ResourceRequest resourceRequest = getResourceRequest(expansions);
EnvironmentDTO dto = environmentBuilder.buildItems(uriInfo, resourceRequest, project);
return Response.ok().entity(dto).build();
}
Aggregations