Github user revans2 commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1642#discussion_r77527879
  
    --- Diff: storm-core/src/jvm/org/apache/storm/localizer/AsyncLocalizer.java 
---
    @@ -0,0 +1,420 @@
    +/**
    + * 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.storm.localizer;
    +
    +import java.io.File;
    +import java.io.FileOutputStream;
    +import java.io.IOException;
    +import java.net.JarURLConnection;
    +import java.net.URL;
    +import java.util.ArrayList;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.Callable;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.Future;
    +import java.util.concurrent.TimeUnit;
    +
    +import org.apache.commons.io.FileUtils;
    +import org.apache.storm.Config;
    +import org.apache.storm.blobstore.BlobStore;
    +import org.apache.storm.blobstore.ClientBlobStore;
    +import org.apache.storm.daemon.Shutdownable;
    +import org.apache.storm.daemon.supervisor.AdvancedFSOps;
    +import org.apache.storm.daemon.supervisor.SupervisorUtils;
    +import org.apache.storm.generated.StormTopology;
    +import org.apache.storm.utils.ConfigUtils;
    +import org.apache.storm.utils.Utils;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.google.common.util.concurrent.ThreadFactoryBuilder;
    +
    +/**
    + * This is a wrapper around the Localizer class that provides the desired
    + * async interface to Slot.
    + * TODO once we have replaced the original supervisor merge this with
    + * Localizer and optimize them
    + */
    +public class AsyncLocalizer implements ILocalizer, Shutdownable {
    +    /**
    +     * A future that has already completed.
    +     */
    +    private static class AllDoneFuture implements Future<Void> {
    +
    +        @Override
    +        public boolean cancel(boolean mayInterruptIfRunning) {
    +            return false;
    +        }
    +
    +        @Override
    +        public boolean isCancelled() {
    +            return false;
    +        }
    +
    +        @Override
    +        public boolean isDone() {
    +            return true;
    +        }
    +
    +        @Override
    +        public Void get() {
    +            return null;
    +        }
    +
    +        @Override
    +        public Void get(long timeout, TimeUnit unit) {
    +            return null;
    +        }
    +
    +    }
    +
    +    private static final Logger LOG = 
LoggerFactory.getLogger(AsyncLocalizer.class);
    +
    +    private final Localizer _localizer;
    +    private final ExecutorService _execService;
    +    private final boolean _isLocalMode;
    +    private final Map<String, Object> _conf;
    +    private final Map<String, LocalDownloadedResource> _basicPending;
    +    private final Map<String, LocalDownloadedResource> _blobPending;
    +    private final AdvancedFSOps _fsOps;
    +
    +    private class DownloadBaseBlobsDistributed implements Callable<Void> {
    +        private final String _topologyId;
    +        
    +        public DownloadBaseBlobsDistributed(String topologyId) {
    +            this._topologyId = topologyId;
    +        }
    +        
    +        @Override
    +        public Void call() throws Exception {
    +            String stormroot = ConfigUtils.supervisorStormDistRoot(_conf, 
_topologyId);
    +            File sr = new File(stormroot);
    +            if (sr.exists()) {
    +                if (!_fsOps.supportsAtomicDirectoryMove()) {
    +                    LOG.warn("{} may have partially downloaded blobs, 
recovering", _topologyId);
    +                    Utils.forceDelete(stormroot);
    +                } else {
    +                    LOG.warn("{} already downloaded blobs, skipping", 
_topologyId);
    +                    return null;
    +                }
    +            }
    --- End diff --
    
    I refactored this instead so the code is shared by a single class.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to