Skip to content

Commit

Permalink
[HWORKS-545][APPEND] bug fix - deleted source fg, update access - dat…
Browse files Browse the repository at this point in the history
…a scientist has only read (#1541)
  • Loading branch information
o-alex committed Sep 8, 2023
1 parent 656de2f commit 3cd5f9f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private URI uri(UriInfo uriInfo, Project project,
private URI uri(UriInfo uriInfo, Project project,
Featurestore featurestore, TrainingDataset trainingDataset) {
return uri(uriInfo, project, featurestore)
.path(ResourceRequest.Name.FEATUREGROUPS.toString().toLowerCase())
.path(ResourceRequest.Name.TRAININGDATASETS.toString().toLowerCase())
.path(Integer.toString(trainingDataset.getId()))
.path(ResourceRequest.Name.KEYWORDS.toString().toLowerCase())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@
import io.hops.hopsworks.api.filter.AllowedProjectRoles;
import io.hops.hopsworks.api.filter.Audience;
import io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired;
import io.hops.hopsworks.api.jwt.JWTHelper;
import io.hops.hopsworks.common.api.ResourceRequest;
import io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupController;
import io.hops.hopsworks.common.featurestore.keyword.KeywordDTO;
import io.hops.hopsworks.common.featurestore.metadata.FeatureStoreKeywordControllerIface;
import io.hops.hopsworks.exceptions.FeaturestoreException;
import io.hops.hopsworks.exceptions.MetadataException;
import io.hops.hopsworks.jwt.annotation.JWTRequired;
import io.hops.hopsworks.persistence.entity.featurestore.Featurestore;
import io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup;
import io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView;
import io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset;
import io.hops.hopsworks.persistence.entity.project.Project;
import io.hops.hopsworks.persistence.entity.user.Users;
import io.hops.hopsworks.persistence.entity.user.security.apiKey.ApiScope;
import io.hops.hopsworks.restutils.RESTCodes;
import io.swagger.annotations.Api;
Expand Down Expand Up @@ -70,8 +67,6 @@ public class FeaturestoreKeywordResource {
@EJB
private FeatureViewController featureViewController;
@EJB
private JWTHelper jwtHelper;
@EJB
private FeaturestoreKeywordBuilder featurestoreKeywordBuilder;
@Inject
private FeatureStoreKeywordControllerIface keywordCtrl;
Expand Down Expand Up @@ -137,7 +132,7 @@ public Response getKeywords(@Context SecurityContext sc,
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create keywords or replace existing ones")
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
Expand Down Expand Up @@ -169,7 +164,7 @@ public Response replaceKeywords(@Context SecurityContext sc,

@DELETE
@ApiOperation(value = "Delete a keyword")
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
Expand All @@ -178,9 +173,7 @@ public Response deleteKeywords(@Context SecurityContext sc,
@Context UriInfo uriInfo,
@Context HttpServletRequest req,
@QueryParam("keyword") String keyword)
throws FeaturestoreException, MetadataException {
Users user = jwtHelper.getUserPrincipal(sc);

throws FeaturestoreException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KEYWORDS);
KeywordDTO dto;
if (featuregroup != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ protected abstract TagsDTO buildGetTags(UriInfo uriInfo, ResourceRequest request
@Path("/{name}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER"})
public Response putTag(@Context SecurityContext sc,
@Context HttpServletRequest req,
@Context UriInfo uriInfo,
Expand All @@ -132,7 +132,7 @@ public Response putTag(@Context SecurityContext sc,
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
Expand Down Expand Up @@ -162,7 +162,7 @@ public Response putTags(@Context SecurityContext sc, @Context UriInfo uriInfo,
@ApiOperation( value = "Get all tags attached", response = TagsDTO.class)
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
Expand All @@ -182,7 +182,7 @@ public Response getTags(@Context SecurityContext sc, @Context UriInfo uriInfo,
@GET
@Path("/{name}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
Expand All @@ -209,7 +209,7 @@ public Response getTag(@Context SecurityContext sc, @Context UriInfo uriInfo,
@ApiOperation( value = "Delete all attached tags")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
Expand All @@ -225,7 +225,7 @@ public Response deleteTags(@Context SecurityContext sc,
@DELETE
@Path("/{name}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER})
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER})
@JWTRequired(acceptedTokens = {Audience.API, Audience.JOB},
allowedUserRoles = {"HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER"})
@ApiKeyRequired(acceptedScopes = {ApiScope.FEATURESTORE},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void process() {
try {
processInt();
} catch (Exception t) {
LOGGER.log(Level.INFO, "Command processing failed with error:", t);
LOGGER.log(Level.INFO, "Command processing failed with error:", t.getStackTrace());
}
}
schedule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ private FeaturegroupXAttr.FullDTO getFGXAttr(FeaturegroupDTO dto) {
private FeatureViewXAttrDTO getFVXAttr(FeatureView featureView) {
Map<Integer, FeaturegroupXAttr.SimplifiedDTO> featuregroups = new HashMap<>();
for(TrainingDatasetFeature feature : featureView.getFeatures()) {
FeaturegroupXAttr.SimplifiedDTO featuregroup = featuregroups.get(feature.getFeatureGroup().getId());
if(featuregroup == null) {
featuregroup = new FeaturegroupXAttr.SimplifiedDTO(feature.getFeatureGroup().getFeaturestore().getId(),
feature.getFeatureGroup().getName(), feature.getFeatureGroup().getVersion());
featuregroups.put(feature.getFeatureGroup().getId(), featuregroup);
if (feature.getFeatureGroup() != null) {
FeaturegroupXAttr.SimplifiedDTO featuregroup = featuregroups.get(feature.getFeatureGroup().getId());
if (featuregroup == null) {
featuregroup = new FeaturegroupXAttr.SimplifiedDTO(feature.getFeatureGroup().getFeaturestore().getId(),
feature.getFeatureGroup().getName(), feature.getFeatureGroup().getVersion());
featuregroups.put(feature.getFeatureGroup().getId(), featuregroup);
}
featuregroup.addFeature(feature.getName());
}
featuregroup.addFeature(feature.getName());
}
return new FeatureViewXAttrDTO(featureView.getFeaturestore().getId(),
featureView.getDescription(),
Expand Down Expand Up @@ -274,13 +276,15 @@ private TrainingDatasetXAttrDTO getTDXAttr(TrainingDatasetDTO trainingDatasetDTO
private List<FeaturegroupXAttr.SimplifiedDTO> fromTrainingDatasetQuery(TrainingDatasetDTO trainingDatasetDTO) {
Map<Integer, FeaturegroupXAttr.SimplifiedDTO> featuregroups = new HashMap<>();
for(TrainingDatasetFeatureDTO feature : trainingDatasetDTO.getFeatures()) {
FeaturegroupXAttr.SimplifiedDTO featuregroup = featuregroups.get(feature.getFeaturegroup().getId());
if(featuregroup == null) {
featuregroup = new FeaturegroupXAttr.SimplifiedDTO(feature.getFeaturegroup().getFeaturestoreId(),
feature.getFeaturegroup().getName(), feature.getFeaturegroup().getVersion());
featuregroups.put(feature.getFeaturegroup().getId(), featuregroup);
if(feature.getFeaturegroup() != null) {
FeaturegroupXAttr.SimplifiedDTO featuregroup = featuregroups.get(feature.getFeaturegroup().getId());
if (featuregroup == null) {
featuregroup = new FeaturegroupXAttr.SimplifiedDTO(feature.getFeaturegroup().getFeaturestoreId(),
feature.getFeaturegroup().getName(), feature.getFeaturegroup().getVersion());
featuregroups.put(feature.getFeaturegroup().getId(), featuregroup);
}
featuregroup.addFeature(feature.getName());
}
featuregroup.addFeature(feature.getName());
}
return new ArrayList<>(featuregroups.values());
}
Expand Down

0 comments on commit 3cd5f9f

Please sign in to comment.