2015-11-03 09:53:21 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2015 ScyllaDB
|
|
|
|
*
|
|
|
|
* Modified by ScyllaDB
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.apache.cassandra.streaming;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2016-10-11 14:07:25 +02:00
|
|
|
import java.util.logging.Logger;
|
2015-11-03 09:53:21 +01:00
|
|
|
|
|
|
|
import javax.json.JsonArray;
|
|
|
|
import javax.json.JsonObject;
|
|
|
|
import javax.management.ListenerNotFoundException;
|
|
|
|
import javax.management.MBeanNotificationInfo;
|
2016-10-11 14:07:25 +02:00
|
|
|
import javax.management.NotificationBroadcasterSupport;
|
2015-11-03 09:53:21 +01:00
|
|
|
import javax.management.NotificationFilter;
|
|
|
|
import javax.management.NotificationListener;
|
|
|
|
import javax.management.openmbean.CompositeData;
|
|
|
|
|
|
|
|
import org.apache.cassandra.streaming.management.StreamStateCompositeData;
|
|
|
|
|
|
|
|
import com.google.common.collect.Iterables;
|
|
|
|
import com.google.common.collect.Sets;
|
2015-12-17 08:26:19 +01:00
|
|
|
import com.scylladb.jmx.api.APIClient;
|
2016-10-11 14:07:25 +02:00
|
|
|
import com.scylladb.jmx.metrics.APIMBean;
|
2015-11-03 09:53:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* StreamManager manages currently running {@link StreamResultFuture}s and
|
|
|
|
* provides status of all operation invoked.
|
|
|
|
*
|
|
|
|
* All stream operation should be created through this class to track streaming
|
|
|
|
* status and progress.
|
|
|
|
*/
|
2016-10-11 14:07:25 +02:00
|
|
|
public class StreamManager extends APIMBean implements StreamManagerMBean {
|
|
|
|
private static final Logger logger = Logger.getLogger(StreamManager.class.getName());
|
|
|
|
|
|
|
|
private final NotificationBroadcasterSupport notifier = new NotificationBroadcasterSupport();
|
|
|
|
|
|
|
|
public StreamManager(APIClient c) {
|
|
|
|
super(c);
|
|
|
|
}
|
2015-11-03 09:53:21 +01:00
|
|
|
|
|
|
|
public Set<StreamState> getState() {
|
2016-10-11 14:07:25 +02:00
|
|
|
JsonArray arr = client.getJsonArray("/stream_manager/");
|
2015-11-03 09:53:21 +01:00
|
|
|
Set<StreamState> res = new HashSet<StreamState>();
|
|
|
|
for (int i = 0; i < arr.size(); i++) {
|
|
|
|
JsonObject obj = arr.getJsonObject(i);
|
2016-10-11 14:07:25 +02:00
|
|
|
res.add(new StreamState(obj.getString("plan_id"), obj.getString("description"),
|
|
|
|
SessionInfo.fromJsonArr(obj.getJsonArray("sessions"))));
|
2015-11-03 09:53:21 +01:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-10-11 14:07:25 +02:00
|
|
|
@Override
|
2015-11-03 09:53:21 +01:00
|
|
|
public Set<CompositeData> getCurrentStreams() {
|
2015-12-30 07:47:32 +01:00
|
|
|
logger.finest("getCurrentStreams");
|
2016-10-11 14:07:25 +02:00
|
|
|
return Sets
|
|
|
|
.newHashSet(Iterables.transform(getState(), input -> StreamStateCompositeData.toCompositeData(input)));
|
2015-11-03 09:53:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-11 14:07:25 +02:00
|
|
|
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
|
|
|
|
notifier.addNotificationListener(listener, filter, handback);
|
2015-11-03 09:53:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-11 14:07:25 +02:00
|
|
|
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
|
|
|
|
notifier.removeNotificationListener(listener);
|
2015-11-03 09:53:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-11 14:07:25 +02:00
|
|
|
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
|
|
|
|
throws ListenerNotFoundException {
|
|
|
|
notifier.removeNotificationListener(listener, filter, handback);
|
2015-11-03 09:53:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-11 14:07:25 +02:00
|
|
|
public MBeanNotificationInfo[] getNotificationInfo() {
|
|
|
|
return notifier.getNotificationInfo();
|
2015-11-03 09:53:21 +01:00
|
|
|
}
|
|
|
|
}
|