-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NXP-32515: Propagate retrieve requests
- Loading branch information
Showing
4 changed files
with
160 additions
and
17 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
...main/java/org/nuxeo/coldstorage/action/PropagateRetrieveFromColdStorageContentAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* (C) Copyright 2024 Nuxeo (http://nuxeo.com/) and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Contributors: | ||
* Guillaume Renard | ||
*/ | ||
|
||
package org.nuxeo.coldstorage.action; | ||
|
||
import static org.nuxeo.ecm.core.bulk.BulkServiceImpl.STATUS_STREAM; | ||
import static org.nuxeo.lib.stream.computation.AbstractComputation.INPUT_1; | ||
import static org.nuxeo.lib.stream.computation.AbstractComputation.OUTPUT_1; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.nuxeo.coldstorage.ColdStorageConstants; | ||
import org.nuxeo.coldstorage.service.ColdStorageService; | ||
import org.nuxeo.ecm.core.api.CoreSession; | ||
import org.nuxeo.ecm.core.api.DocumentModel; | ||
import org.nuxeo.ecm.core.api.DocumentModelList; | ||
import org.nuxeo.ecm.core.api.NuxeoException; | ||
import org.nuxeo.ecm.core.bulk.action.computation.AbstractBulkComputation; | ||
import org.nuxeo.lib.stream.computation.Topology; | ||
import org.nuxeo.runtime.api.Framework; | ||
import org.nuxeo.runtime.stream.StreamProcessorTopology; | ||
|
||
/** | ||
* Bulk action in charge of marking documents being retrieved. | ||
* | ||
* @since 2023.4 | ||
*/ | ||
public class PropagateRetrieveFromColdStorageContentAction implements StreamProcessorTopology { | ||
|
||
private static final Logger log = LogManager.getLogger(PropagateRetrieveFromColdStorageContentAction.class); | ||
|
||
public static final String ACTION_NAME = "propagateRetrieveFromColdStorage"; | ||
|
||
public static final String ACTION_FULL_NAME = "bulk/" + ACTION_NAME; | ||
|
||
@Override | ||
public Topology getTopology(Map<String, String> options) { | ||
return Topology.builder() | ||
.addComputation(PropagateRetrieveFromColdStorageContentComputation::new, // | ||
List.of(INPUT_1 + ":" + ACTION_FULL_NAME, OUTPUT_1 + ":" + STATUS_STREAM)) | ||
.build(); | ||
} | ||
|
||
public static class PropagateRetrieveFromColdStorageContentComputation extends AbstractBulkComputation { | ||
|
||
public PropagateRetrieveFromColdStorageContentComputation() { | ||
super(ACTION_FULL_NAME); | ||
} | ||
|
||
@Override | ||
protected void compute(CoreSession session, List<String> ids, Map<String, Serializable> properties) { | ||
log.debug("Start computing documents of which a retrieve from ColdStorage is ongoing {}", ids); | ||
DocumentModelList documents = loadDocuments(session, ids); | ||
|
||
ColdStorageService service = Framework.getService(ColdStorageService.class); | ||
|
||
long errorCount = 0; | ||
for (DocumentModel document : documents) { | ||
if (!document.hasFacet(ColdStorageConstants.COLD_STORAGE_FACET_NAME)) { | ||
log.info("The main content for document: {} is not in cold storage.", document::getId); | ||
continue; | ||
} | ||
try { | ||
service.proceedRetrieveMainContent(session, document); | ||
} catch (NuxeoException e) { | ||
errorCount++; | ||
delta.inError(String.format("Cannot propagate retrieve from cold storage for document %s: %s", document.getId(), | ||
e.getMessage())); | ||
log.warn("Could not propagate retrieve from cold storage for document: {}", document::getId, | ||
() -> e); | ||
} | ||
} | ||
delta.setErrorCount(errorCount); | ||
log.debug("End computing documents of which a retrieve from ColdStorage is ongoing"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters