jack-moseley commented on a change in pull request #2620: [GOBBLIN-756] Add flow catalog that updates when filesystem is modified URL: https://github.com/apache/incubator-gobblin/pull/2620#discussion_r279581690
########## File path: gobblin-service/src/main/java/org/apache/gobblin/service/modules/template_catalog/UpdatingFSFlowTemplateCatalog.java ########## @@ -0,0 +1,108 @@ +/* + * 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.gobblin.service.modules.template_catalog; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.hadoop.fs.Path; + +import com.typesafe.config.Config; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.runtime.api.JobTemplate; +import org.apache.gobblin.runtime.api.SpecNotFoundException; +import org.apache.gobblin.service.modules.template.FlowTemplate; +import org.apache.gobblin.util.filesystem.PathAlterationListener; +import org.apache.gobblin.util.filesystem.PathAlterationListenerAdaptor; + + +/** + * {@link FSFlowTemplateCatalog} that keeps a cache of flow and job templates. It has a + * {@link org.apache.gobblin.util.filesystem.PathAlterationListener} on the root path, and clears the cache when a change + * is detected so that the next call to {@link #getFlowTemplate(URI)} will use the updated files. + */ +@Slf4j +public class UpdatingFSFlowTemplateCatalog extends FSFlowTemplateCatalog { + private static Map<URI, FlowTemplate> flowTemplateMap = new ConcurrentHashMap<>(); + private static Map<URI, List<JobTemplate>> jobTemplateMap = new ConcurrentHashMap<>(); + + public UpdatingFSFlowTemplateCatalog(Config sysConfig) throws IOException { + super(sysConfig); + } + + @Override + public FlowTemplate getFlowTemplate(URI flowTemplateDirURI) Review comment: Updated to use a thread-safe way of getting flow template from map. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
