Search in sources :

Example 1 with LocalizedResource

use of org.apache.storm.localizer.LocalizedResource in project storm by apache.

the class AsyncLocalizerTest method testRequestDownloadTopologyBlobs.

@Test
public void testRequestDownloadTopologyBlobs() throws Exception {
    final String topoId = "TOPO-12345";
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    ExecutorInfo ei = new ExecutorInfo();
    ei.set_task_start(1);
    ei.set_task_end(1);
    la.add_to_executors(ei);
    final String topoName = "TOPO";
    final int port = 8080;
    final String user = "user";
    final String simpleLocalName = "simple.txt";
    final String simpleKey = "simple";
    final String stormLocal = "/tmp/storm-local/";
    final File userDir = new File(stormLocal, user);
    final String stormRoot = stormLocal + topoId + "/";
    final String localizerRoot = "/tmp/storm-localizer/";
    final String simpleLocalFile = localizerRoot + user + "/simple";
    final String simpleCurrentLocalFile = localizerRoot + user + "/simple.current";
    final StormTopology st = new StormTopology();
    st.set_spouts(new HashMap<>());
    st.set_bolts(new HashMap<>());
    st.set_state_spouts(new HashMap<>());
    Map<String, Map<String, Object>> topoBlobMap = new HashMap<>();
    Map<String, Object> simple = new HashMap<>();
    simple.put("localname", simpleLocalName);
    simple.put("uncompress", false);
    topoBlobMap.put(simpleKey, simple);
    Map<String, Object> conf = new HashMap<>();
    conf.put(Config.STORM_LOCAL_DIR, stormLocal);
    Localizer localizer = mock(Localizer.class);
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    ConfigUtils mockedCU = mock(ConfigUtils.class);
    Utils mockedU = mock(Utils.class);
    Map<String, Object> topoConf = new HashMap<>(conf);
    topoConf.put(Config.TOPOLOGY_BLOBSTORE_MAP, topoBlobMap);
    topoConf.put(Config.TOPOLOGY_SUBMITTER_USER, user);
    topoConf.put(Config.TOPOLOGY_NAME, topoName);
    List<LocalizedResource> localizedList = new ArrayList<>();
    LocalizedResource simpleLocal = new LocalizedResource(simpleKey, simpleLocalFile, false);
    localizedList.add(simpleLocal);
    AsyncLocalizer al = new AsyncLocalizer(conf, localizer, ops);
    ConfigUtils orig = ConfigUtils.setInstance(mockedCU);
    Utils origUtils = Utils.setInstance(mockedU);
    try {
        when(mockedCU.supervisorStormDistRootImpl(conf, topoId)).thenReturn(stormRoot);
        when(mockedCU.readSupervisorStormConfImpl(conf, topoId)).thenReturn(topoConf);
        when(mockedCU.readSupervisorTopologyImpl(conf, topoId, ops)).thenReturn(st);
        when(localizer.getLocalUserFileCacheDir(user)).thenReturn(userDir);
        when(localizer.getBlobs(any(List.class), eq(user), eq(topoName), eq(userDir))).thenReturn(localizedList);
        Future<Void> f = al.requestDownloadTopologyBlobs(la, port);
        f.get(20, TimeUnit.SECONDS);
        // We should be done now...
        verify(localizer).getLocalUserFileCacheDir(user);
        verify(ops).fileExists(userDir);
        verify(ops).forceMkdir(userDir);
        verify(localizer).getBlobs(any(List.class), eq(user), eq(topoName), eq(userDir));
        verify(ops).createSymlink(new File(stormRoot, simpleLocalName), new File(simpleCurrentLocalFile));
    } finally {
        al.shutdown();
        ConfigUtils.setInstance(orig);
        Utils.setInstance(origUtils);
    }
}
Also used : HashMap(java.util.HashMap) LocalizedResource(org.apache.storm.localizer.LocalizedResource) StormTopology(org.apache.storm.generated.StormTopology) ConfigUtils(org.apache.storm.utils.ConfigUtils) ArrayList(java.util.ArrayList) Localizer(org.apache.storm.localizer.Localizer) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) Utils(org.apache.storm.utils.Utils) ConfigUtils(org.apache.storm.utils.ConfigUtils) LocalAssignment(org.apache.storm.generated.LocalAssignment) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) AdvancedFSOps(org.apache.storm.daemon.supervisor.AdvancedFSOps) Test(org.junit.Test)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AdvancedFSOps (org.apache.storm.daemon.supervisor.AdvancedFSOps)1 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)1 LocalAssignment (org.apache.storm.generated.LocalAssignment)1 StormTopology (org.apache.storm.generated.StormTopology)1 LocalizedResource (org.apache.storm.localizer.LocalizedResource)1 Localizer (org.apache.storm.localizer.Localizer)1 ConfigUtils (org.apache.storm.utils.ConfigUtils)1 Utils (org.apache.storm.utils.Utils)1 Test (org.junit.Test)1