mneethiraj commented on code in PR #307: URL: https://github.com/apache/atlas/pull/307#discussion_r1994379497
########## repository/src/main/java/org/apache/atlas/repository/impexp/AsyncImportService.java: ########## @@ -0,0 +1,222 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.atlas.repository.impexp; + +import org.apache.atlas.AtlasErrorCode; +import org.apache.atlas.SortOrder; +import org.apache.atlas.annotation.GraphTransaction; +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.impexp.AtlasAsyncImportRequest; +import org.apache.atlas.repository.ogm.DataAccess; +import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.ObjectUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import static org.apache.atlas.model.impexp.AtlasAsyncImportRequest.ASYNC_IMPORT_TYPE_NAME; +import static org.apache.atlas.model.impexp.AtlasAsyncImportRequest.ImportStatus.ABORTED; +import static org.apache.atlas.model.impexp.AtlasAsyncImportRequest.ImportStatus.PROCESSING; +import static org.apache.atlas.model.impexp.AtlasAsyncImportRequest.ImportStatus.WAITING; + +@Service +public class AsyncImportService { + private static final Logger LOG = LoggerFactory.getLogger(AsyncImportService.class); + + private final DataAccess dataAccess; + + @Inject + public AsyncImportService(DataAccess dataAccess) { + this.dataAccess = dataAccess; + } + + public synchronized AtlasAsyncImportRequest fetchImportRequestByImportId(String importId) { + try { + AtlasAsyncImportRequest request = new AtlasAsyncImportRequest(); + request.setImportId(importId); + + return dataAccess.load(request); + } catch (Exception e) { + LOG.error("Error fetching request with importId: {}", importId, e); + return null; + } + } + + public void saveImportRequest(AtlasAsyncImportRequest importRequest) throws AtlasBaseException { + try { + dataAccess.save(importRequest); + LOG.debug("Save request ID: {} request: {}", importRequest.getImportId(), importRequest.toString()); + } catch (AtlasBaseException e) { + throw e; + } + } + + public void updateImportRequest(AtlasAsyncImportRequest importRequest) { + try { + saveImportRequest(importRequest); + } catch (AtlasBaseException abe) { + LOG.error("Failed to update import: {} with request: {}", importRequest.getImportId(), importRequest.toString()); + } + } + + public synchronized List<String> fetchInProgressImportIds() { + List<String> guids = AtlasGraphUtilsV2.findEntityGUIDsByType(ASYNC_IMPORT_TYPE_NAME, SortOrder.ASCENDING); Review Comment: Insteaf of retrieving all AtlasAsyncImportRequest instances and looking for those in PROCESSING status (line 107 below), consider adding a method to only retrieve guid of requests having relevant status - something along the lines of: ``` AtlaGraphUtilsV2.findByTypeAndAttributes(ASYNC_IMPORT_TYPE_NAME, Collections.singletonMap(AtlasAsyncImportRequestDTO.STATUS_PROPERTY, PROCESSING)) ``` Such method could be used in `fetchQueuedImportRequests()` as well, to retrieve requests in `WAITING` status. Also, existing method `findEntityGUIDsByType()` performs sorting by `qualifiedName` attribute; is that useful here? Perhaps `createTime` might be more useful for import-requests? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@atlas.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org