use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project fabric8 by jboss-fuse.
the class FabricMBeanRegistrationListener method registerDomains.
private void registerDomains() throws Exception {
String runtimeIdentity = runtimeProperties.get().getRuntimeIdentity();
String domainsNode = CONTAINER_DOMAINS.getPath(runtimeIdentity);
try {
Stat stat = exists(curator.get(), domainsNode);
if (stat != null) {
try {
deleteSafe(curator.get(), domainsNode);
} catch (IllegalStateException e) {
handleException(e);
}
}
synchronized (this) {
domains.addAll(Arrays.asList(mbeanServer.get().getDomains()));
for (String domain : domains) {
try {
setData(curator.get(), CONTAINER_DOMAIN.getPath(runtimeIdentity, domain), "", CreateMode.EPHEMERAL);
} catch (IllegalStateException e) {
handleException(e);
}
}
}
} catch (IllegalStateException e) {
handleException(e);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project fabric8 by jboss-fuse.
the class FabricMBeanRegistrationListener method updateProcessId.
private void updateProcessId() {
try {
// TODO: this is Sun JVM specific ...
// String processName = (String) mbeanServer.get().getAttribute(new ObjectName("java.lang:type=Runtime"), "Name");
String processName = ManagementFactory.getRuntimeMXBean().getName();
Long processId = Long.parseLong(processName.split("@")[0]);
String runtimeIdentity = runtimeProperties.get().getRuntimeIdentity();
String path = ZkPath.CONTAINER_PROCESS_ID.getPath(runtimeIdentity);
Stat stat = exists(curator.get(), path);
if (stat != null) {
if (stat.getEphemeralOwner() != curator.get().getZookeeperClient().getZooKeeper().getSessionId()) {
delete(curator.get(), path);
if (processId != null) {
create(curator.get(), path, processId.toString(), CreateMode.EPHEMERAL);
}
}
} else {
if (processId != null) {
create(curator.get(), path, processId.toString(), CreateMode.EPHEMERAL);
}
}
} catch (IllegalStateException e) {
handleException(e);
} catch (Exception ex) {
LOGGER.error("Error while updating the process id.", ex);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project accumulo by apache.
the class MiniAccumuloClusterImpl method start.
/**
* Starts Accumulo and Zookeeper processes. Can only be called once.
*/
@Override
public synchronized void start() throws IOException, InterruptedException {
if (config.useMiniDFS() && miniDFS == null) {
throw new IllegalStateException("Cannot restart mini when using miniDFS");
}
MiniAccumuloClusterControl control = getClusterControl();
if (config.useExistingInstance()) {
Configuration acuConf = config.getAccumuloConfiguration();
Configuration hadoopConf = config.getHadoopConfiguration();
ConfigurationCopy cc = new ConfigurationCopy(acuConf);
VolumeManager fs;
try {
fs = VolumeManagerImpl.get(cc, hadoopConf);
} catch (IOException e) {
throw new RuntimeException(e);
}
Path instanceIdPath = Accumulo.getAccumuloInstanceIdPath(fs);
String instanceIdFromFile = ZooUtil.getInstanceIDFromHdfs(instanceIdPath, cc, hadoopConf);
IZooReaderWriter zrw = new ZooReaderWriterFactory().getZooReaderWriter(cc.get(Property.INSTANCE_ZK_HOST), (int) cc.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT), cc.get(Property.INSTANCE_SECRET));
String rootPath = ZooUtil.getRoot(instanceIdFromFile);
String instanceName = null;
try {
for (String name : zrw.getChildren(Constants.ZROOT + Constants.ZINSTANCES)) {
String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name;
byte[] bytes = zrw.getData(instanceNamePath, new Stat());
String iid = new String(bytes, UTF_8);
if (iid.equals(instanceIdFromFile)) {
instanceName = name;
}
}
} catch (KeeperException e) {
throw new RuntimeException("Unable to read instance name from zookeeper.", e);
}
if (instanceName == null)
throw new RuntimeException("Unable to read instance name from zookeeper.");
config.setInstanceName(instanceName);
if (!AccumuloStatus.isAccumuloOffline(zrw, rootPath))
throw new RuntimeException("The Accumulo instance being used is already running. Aborting.");
} else {
if (!initialized) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
MiniAccumuloClusterImpl.this.stop();
} catch (IOException e) {
log.error("IOException while attempting to stop the MiniAccumuloCluster.", e);
} catch (InterruptedException e) {
log.error("The stopping of MiniAccumuloCluster was interrupted.", e);
}
}
});
}
if (!config.useExistingZooKeepers())
control.start(ServerType.ZOOKEEPER);
if (!initialized) {
if (!config.useExistingZooKeepers()) {
// sleep a little bit to let zookeeper come up before calling init, seems to work better
long startTime = System.currentTimeMillis();
while (true) {
Socket s = null;
try {
s = new Socket("localhost", config.getZooKeeperPort());
s.setReuseAddress(true);
s.getOutputStream().write("ruok\n".getBytes());
s.getOutputStream().flush();
byte[] buffer = new byte[100];
int n = s.getInputStream().read(buffer);
if (n >= 4 && new String(buffer, 0, 4).equals("imok"))
break;
} catch (Exception e) {
if (System.currentTimeMillis() - startTime >= config.getZooKeeperStartupTime()) {
throw new ZooKeeperBindException("Zookeeper did not start within " + (config.getZooKeeperStartupTime() / 1000) + " seconds. Check the logs in " + config.getLogDir() + " for errors. Last exception: " + e);
}
// Don't spin absurdly fast
Thread.sleep(250);
} finally {
if (s != null)
s.close();
}
}
}
LinkedList<String> args = new LinkedList<>();
args.add("--instance-name");
args.add(config.getInstanceName());
args.add("--user");
args.add(config.getRootUserName());
args.add("--clear-instance-name");
// If we aren't using SASL, add in the root password
final String saslEnabled = config.getSiteConfig().get(Property.INSTANCE_RPC_SASL_ENABLED.getKey());
if (null == saslEnabled || !Boolean.parseBoolean(saslEnabled)) {
args.add("--password");
args.add(config.getRootPassword());
}
Process initProcess = exec(Initialize.class, args.toArray(new String[0]));
int ret = initProcess.waitFor();
if (ret != 0) {
throw new RuntimeException("Initialize process returned " + ret + ". Check the logs in " + config.getLogDir() + " for errors.");
}
initialized = true;
}
}
log.info("Starting MAC against instance {} and zookeeper(s) {}.", config.getInstanceName(), config.getZooKeepers());
control.start(ServerType.TABLET_SERVER);
int ret = 0;
for (int i = 0; i < 5; i++) {
ret = exec(Main.class, SetGoalState.class.getName(), MasterGoalState.NORMAL.toString()).waitFor();
if (ret == 0)
break;
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
if (ret != 0) {
throw new RuntimeException("Could not set master goal state, process returned " + ret + ". Check the logs in " + config.getLogDir() + " for errors.");
}
control.start(ServerType.MASTER);
control.start(ServerType.GARBAGE_COLLECTOR);
if (null == executor) {
executor = Executors.newSingleThreadExecutor();
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project accumulo by apache.
the class Master method getMergeInfo.
public MergeInfo getMergeInfo(Table.ID tableId) {
synchronized (mergeLock) {
try {
String path = ZooUtil.getRoot(getInstance().getInstanceID()) + Constants.ZTABLES + "/" + tableId + "/merge";
if (!ZooReaderWriter.getInstance().exists(path))
return new MergeInfo();
byte[] data = ZooReaderWriter.getInstance().getData(path, new Stat());
DataInputBuffer in = new DataInputBuffer();
in.reset(data, data.length);
MergeInfo info = new MergeInfo();
info.readFields(in);
return info;
} catch (KeeperException.NoNodeException ex) {
log.info("Error reading merge state, it probably just finished");
return new MergeInfo();
} catch (Exception ex) {
log.warn("Unexpected error reading merge state", ex);
return new MergeInfo();
}
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project fabric8 by jboss-fuse.
the class KarafContainerRegistration method checkAlive.
private void checkAlive() throws Exception {
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
String nodeAlive = CONTAINER_ALIVE.getPath(runtimeIdentity);
Stat stat = exists(curator.get(), nodeAlive);
if (stat != null) {
if (stat.getEphemeralOwner() != curator.get().getZookeeperClient().getZooKeeper().getSessionId()) {
delete(curator.get(), nodeAlive);
create(curator.get(), nodeAlive, CreateMode.EPHEMERAL);
}
} else {
create(curator.get(), nodeAlive, CreateMode.EPHEMERAL);
}
}
Aggregations