forked from apache/samza
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAMZA-1089: Runner should support kill and status commands
Author: Jacob Maes <[email protected]> Reviewers: Prateek Maheshwari <[email protected]>,Xinyu Liu <[email protected]> Closes apache#106 from jmakes/samza-1089-2
- Loading branch information
Jacob Maes
committed
Apr 3, 2017
1 parent
101ca43
commit 311f9d1
Showing
18 changed files
with
641 additions
and
157 deletions.
There are no files selected for viewing
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
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
73 changes: 73 additions & 0 deletions
73
samza-core/src/main/java/org/apache/samza/execution/StreamManager.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,73 @@ | ||
/* | ||
* 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.samza.execution; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.apache.samza.system.StreamSpec; | ||
import org.apache.samza.system.SystemAdmin; | ||
import org.apache.samza.system.SystemStreamMetadata; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
public class StreamManager { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(StreamManager.class); | ||
|
||
private final Map<String, SystemAdmin> sysAdmins; | ||
|
||
public StreamManager(Map<String, SystemAdmin> sysAdmins) { | ||
this.sysAdmins = sysAdmins; | ||
} | ||
|
||
public void createStreams(List<StreamSpec> streams) { | ||
Multimap<String, StreamSpec> streamsGroupedBySystem = HashMultimap.create(); | ||
streams.forEach(streamSpec -> | ||
streamsGroupedBySystem.put(streamSpec.getSystemName(), streamSpec)); | ||
|
||
for (Map.Entry<String, Collection<StreamSpec>> entry : streamsGroupedBySystem.asMap().entrySet()) { | ||
String systemName = entry.getKey(); | ||
SystemAdmin systemAdmin = sysAdmins.get(systemName); | ||
|
||
for (StreamSpec stream : entry.getValue()) { | ||
LOGGER.info("Creating stream {} with partitions {} on system {}", | ||
new Object[]{stream.getPhysicalName(), stream.getPartitionCount(), systemName}); | ||
systemAdmin.createStream(stream); | ||
} | ||
} | ||
} | ||
|
||
Map<String, Integer> getStreamPartitionCounts(String systemName, Set<String> streamNames) { | ||
Map<String, Integer> streamToPartitionCount = new HashMap<>(); | ||
|
||
SystemAdmin systemAdmin = sysAdmins.get(systemName); | ||
// retrieve the metadata for the streams in this system | ||
Map<String, SystemStreamMetadata> streamToMetadata = systemAdmin.getSystemStreamMetadata(streamNames); | ||
// set the partitions of a stream to its StreamEdge | ||
streamToMetadata.forEach((stream, data) -> | ||
streamToPartitionCount.put(stream, data.getSystemStreamPartitionMetadata().size())); | ||
|
||
return streamToPartitionCount; | ||
} | ||
} |
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
Oops, something went wrong.