3232import io .hops .hopsworks .persistence .entity .commands .search .SearchFSCommand ;
3333import io .hops .hopsworks .persistence .entity .commands .search .SearchFSCommandHistory ;
3434import io .hops .hopsworks .persistence .entity .commands .search .SearchFSCommandOp ;
35- import io .hops .hopsworks .persistence .entity .project .Project ;
3635import io .hops .hopsworks .restutils .RESTCodes ;
3736
3837import javax .annotation .PostConstruct ;
@@ -138,7 +137,7 @@ public void process() {
138137 try {
139138 processInt ();
140139 } catch (Exception t ) {
141- LOGGER .log (Level .INFO , "Command processing failed with error: " , t . getStackTrace () );
140+ LOGGER .log (Level .INFO , "Command processing failed with error" , t );
142141 }
143142 }
144143 schedule ();
@@ -160,34 +159,32 @@ private void processInt() throws CommandException {
160159 return ;
161160 }
162161 Set <Long > updatingDocs = updatingCommands .stream ().map (this ::getDocId ).collect (Collectors .toSet ());
163- Map <Integer , Project > updatingProjects = updatingCommands .stream ()
164- .collect (Collectors .toMap (c -> c .getProject ().getId (), Command ::getProject , (p1 , p2 ) -> p1 ));
162+ Set <Integer > updatingProjects = updatingCommands .stream ().map (Command ::getProjectId ).collect (Collectors .toSet ());
165163
166164 List <SearchFSCommand > cleaningCommands = commandFacade .findByQuery (queryByStatus (CommandStatus .CLEANING ));
167165 active += cleaningCommands .size ();
168166 if (active >= maxOngoing ) {
169167 return ;
170168 }
171169 Set <Long > cleaningDocs = cleaningCommands .stream ().map (this ::getDocId ).collect (Collectors .toSet ());
172- updatingProjects .putAll (cleaningCommands .stream ().collect (Collectors .toMap (c -> c .getProject ().getId (),
173- Command ::getProject , (existingP , newP ) -> existingP )));
170+ updatingProjects .addAll (cleaningCommands .stream ().map (Command ::getProjectId ).collect (Collectors .toSet ()));
174171
175172 Map <Integer , SearchFSCommand > toDeleteProjects = commandFacade .findByQuery (queryDeletedProjects (CommandStatus .NEW ))
176- .stream ().collect (Collectors .toMap (c -> c . getProject (). getId () , c -> c , (existingC , newC ) -> existingC ));
173+ .stream ().collect (Collectors .toMap (Command :: getProjectId , c -> c , (existingC , newC ) -> existingC ));
177174 Map <Integer , SearchFSCommand > deletingProjects
178175 = commandFacade .findByQuery (queryDeletedProjects (CommandStatus .CLEANING ))
179- .stream ().collect (Collectors .toMap (c -> c . getProject (). getId () , c -> c , (existingC , newC ) -> existingC ));
176+ .stream ().collect (Collectors .toMap (Command :: getProjectId , c -> c , (existingC , newC ) -> existingC ));
180177
181178 List <SearchFSCommand > failedCommands = commandFacade .findByQuery (queryByStatus (CommandStatus .FAILED ));
182179 Set <Long > failedDocs = failedCommands .stream ().map (this ::getDocId ).collect (Collectors .toSet ());
183180
184181 //clean deleted projects that are not actively worked on
185- Set <Integer > deletedAndNotActive = Sets .difference (toDeleteProjects .keySet (), updatingProjects . keySet () );
182+ Set <Integer > deletedAndNotActive = Sets .difference (toDeleteProjects .keySet (), updatingProjects );
186183 for (Integer idx : deletedAndNotActive ) {
187184 cleanDeletedProject (toDeleteProjects .get (idx ));
188185 }
189186 //determine projects to be excluded
190- Set <Project > excludeProjects = unionProjects (toDeleteProjects , deletingProjects );
187+ Set <Integer > excludeProjects = unionProjects (toDeleteProjects , deletingProjects );
191188 //determine documents to be excluded
192189 Set <Long > excludeDocs = new HashSet <>();
193190 excludeDocs .addAll (updatingDocs );
@@ -217,10 +214,10 @@ private void processInt() throws CommandException {
217214 }
218215 }
219216
220- private Set <Project > unionProjects (Map <Integer , SearchFSCommand > p1 , Map <Integer , SearchFSCommand > p2 ) {
221- Set <Project > result = new HashSet <>();
222- p1 .values ().forEach (c -> result .add (c .getProject ()));
223- p2 .values ().forEach (c -> result .add (c .getProject ()));
217+ private Set <Integer > unionProjects (Map <Integer , SearchFSCommand > p1 , Map <Integer , SearchFSCommand > p2 ) {
218+ Set <Integer > result = new HashSet <>();
219+ p1 .values ().forEach (c -> result .add (c .getProjectId ()));
220+ p2 .values ().forEach (c -> result .add (c .getProjectId ()));
224221 return result ;
225222 }
226223
@@ -230,20 +227,20 @@ private void cleanDeletedProject(SearchFSCommand command) {
230227 Try <Boolean > result = processFunction ().apply (command );
231228 try {
232229 if (result .checkedGet ()) {
233- List <SearchFSCommand > toSkip = commandFacade .findByQuery (queryByProject (command .getProject (),
230+ List <SearchFSCommand > toSkip = commandFacade .findByQuery (queryByProject (command .getProjectId (),
234231 SearchFSCommandOp .DELETE_PROJECT ));
235232 toSkip .forEach (c -> removeCommand (c , CommandStatus .SKIPPED ));
236233 removeCommand (command , CommandStatus .SUCCESS );
237234 }
238235 } catch (Throwable t ) {
239236 LOGGER .log (Level .INFO , "Project:{0} clean failed with error:{1}" ,
240- new Object []{command .getProject (). getId (), t .getStackTrace ()});
237+ new Object []{command .getProjectId (), t .getStackTrace ()});
241238 failCommand (command , t .getMessage ());
242239 }
243240 });
244241 }
245242
246- private Set <Long > cleanDeletedArtifacts (Set <Project > excludeProjects , Set <Long > excludeDocs , int maxOngoing )
243+ private Set <Long > cleanDeletedArtifacts (Set <Integer > excludeProjects , Set <Long > excludeDocs , int maxOngoing )
247244 throws CommandException {
248245 Set <Long > deleting = new HashSet <>();
249246 List <SearchFSCommand > toDelete = commandFacade
@@ -276,7 +273,7 @@ private void cleanDeletedArtifact(SearchFSCommand command) {
276273 });
277274 }
278275
279- private Set <Long > cleanDeleteCascadedArtifacts (Set <Project > excludeProjects , Set <Long > excludeDocs , int maxOngoing ) {
276+ private Set <Long > cleanDeleteCascadedArtifacts (Set <Integer > excludeProjects , Set <Long > excludeDocs , int maxOngoing ) {
280277 Set <Long > deleting = new HashSet <>();
281278 List <SearchFSCommand > toDelete = commandFacade .findDeleteCascaded (excludeProjects , excludeDocs , maxOngoing );
282279 for (SearchFSCommand command : toDelete ) {
@@ -298,7 +295,7 @@ private void cleanDeleteCascadedArtifact(SearchFSCommand command) {
298295 cleanDeletedArtifact (deleteArtifact );
299296 }
300297
301- private Set <Long > processArtifacts (Set <Project > excludeProjects , Set <Long > excludeDocs , int maxOngoing ) {
298+ private Set <Long > processArtifacts (Set <Integer > excludeProjects , Set <Long > excludeDocs , int maxOngoing ) {
302299 Set <Long > processing = new HashSet <>();
303300 List <SearchFSCommand > toProcess = commandFacade .findToProcess (excludeProjects , excludeDocs , maxOngoing );
304301 for (SearchFSCommand command : toProcess ) {
@@ -342,9 +339,9 @@ private QueryParam queryDeletedProjects(CommandStatus status) {
342339 return new QueryParam (null , null , filters , null );
343340 }
344341
345- private QueryParam queryByProject (Project project , SearchFSCommandOp notOp ) {
342+ private QueryParam queryByProject (Integer projectId , SearchFSCommandOp notOp ) {
346343 Set <AbstractFacade .FilterBy > filters = new HashSet <>();
347- filters .add (new CommandFilterBy (CommandFacade .Filters .PROJECT_ID_EQ , project . getId () .toString ()));
344+ filters .add (new CommandFilterBy (CommandFacade .Filters .PROJECT_ID_EQ , projectId .toString ()));
348345 filters .add (new CommandFilterBy (SearchFSCommandFacade .SearchFSFilters .OP_NEQ , notOp .name ()));
349346 return new QueryParam (null , null , filters , null );
350347 }
@@ -420,7 +417,7 @@ private Function<SearchFSCommand, Try<Boolean>> processFunction() {
420417 private Try <Boolean > processCommand (SearchFSCommand c ) {
421418 try {
422419 if (c .getOp ().equals (SearchFSCommandOp .DELETE_PROJECT )) {
423- searchController .deleteProject (c .getProject ());
420+ searchController .deleteProject (c .getProjectId ());
424421 return Try .apply (() -> true );
425422 } else if (c .getOp ().equals (SearchFSCommandOp .DELETE_ARTIFACT )) {
426423 searchController .delete (c .getInodeId ());
0 commit comments