List of usage examples for org.apache.zookeeper KeeperException.NoNodeException getMessage
@Override
public String getMessage()
From source file:basestormkafka.DynamicBrokersReader.java
License:Apache License
/** * Get all partitions with their current leaders *//*from w w w. j a v a 2 s. c om*/ public GlobalPartitionInformation getBrokerInfo(String topic) throws SocketTimeoutException { GlobalPartitionInformation globalPartitionInformation = new GlobalPartitionInformation(); try { int numPartitionsForTopic = getNumPartitions(topic); String brokerInfoPath = brokerPath(); for (int partition = 0; partition < numPartitionsForTopic; partition++) { int leader = getLeaderFor(partition, topic); String path = brokerInfoPath + "/" + leader;///kafka/brokers/ids/0 try { byte[] brokerData = _curator.getData().forPath(path); Broker hp = getBrokerHost(brokerData); globalPartitionInformation.addPartition(new PartitioinKey(partition, topic), hp); } catch (org.apache.zookeeper.KeeperException.NoNodeException e) { LOG.error("Node {} does not exist ", path); } } } catch (SocketTimeoutException e) { throw e; } catch (Exception e) { String message = e.getMessage(); if (message.contains("org.apache.zookeeper.KeeperException$NoNodeException")) { return globalPartitionInformation; } else { throw new RuntimeException(e); } } LOG.info("Read partition info from zookeeper: " + globalPartitionInformation); return globalPartitionInformation; }
From source file:com.navercorp.nbasearc.confmaster.server.command.ClusterService.java
License:Apache License
@CommandMapping(name = "appdata_set", arityType = GREATER, usage = "appdata_set <cluster_name> backup <backup_id> <daemon_id> <period> <base_time> <holding period(day)> <net_limit(MB/s)> <output_format> [<service url>]\r\n" + "Ex) appdata_set c1 backup 1 1 0 2 * * * * 02:00:00 3 70 base32hex rsync -az {FILE_PATH} 192.168.0.1::TEST/{MACHINE_NAME}-{CLUSTER_NAME}-{DATE}.json", requiredState = ConfMaster.RUNNING, requiredMode = CLUSTER_ON) public String clusterBackupScheduleSet(@ClusterHint String clusterName, String type, Integer backupID, Integer daemonID, String minute, String hour, String day, String month, String dayOfWeek, String year, String baseTime, Integer holdingPeriod, Integer netLimit, String outputFormat, @Param(type = STRING_VARG) String... serviceURLArgs) throws MgmtZooKeeperException, NodeExistsException { type = type.toLowerCase();/*from w w w.j ava2 s .c o m*/ StringBuilder serviceURLBuilder = new StringBuilder(); String serviceURL; if (serviceURLArgs.length > 0) { for (int i = 0; i < serviceURLArgs.length; i++) { serviceURLBuilder.append(serviceURLArgs[i].trim()).append(" "); } serviceURL = serviceURLBuilder.toString().trim(); } else { serviceURL = ""; } /* * This cronExpression is used by python apscheduler-2.1.2. * Apscheduler defines cron expression as below. * (https://apscheduler.readthedocs.org/en/latest/modules/triggers/cron.html#module-apscheduler.triggers.cron) * * Apscheduler cron expression * --------------------------- * minute 0-59 * hour 0-23 * day of month 1-31 * month 1-12 * day_of_week 0-6 or mon,tue,wed,thu,fri,sat,sun) * * Spring cron expression * ---------------------- * minute 0-59 * hour 0-23 * day of month 1-31 * month 1-12 (or names, see below) * day of week 0-7 (0 or 7 is Sun, or use names) */ String cronExpression = minute + " " + hour + " " + day + " " + month + " " + dayOfWeek + " " + year; // In order to verify cron expression. new CronTrigger(cronExpression); ClusterBackupSchedule.ClusterBackupScheduleData arg; arg = new ClusterBackupSchedule.ClusterBackupScheduleData(); arg.setCluster_name(clusterName); arg.setType(type); arg.setBackup_id(backupID); arg.setDaemon_id(daemonID); arg.setPeriod(cronExpression); arg.setBase_time(baseTime); arg.setHolding_period(holdingPeriod); arg.setNet_limit(netLimit); arg.setOutput_format(outputFormat); arg.setService_url(serviceURL); Cluster cluster = container.getCluster(arg.getCluster_name()); if (cluster == null) { throw new IllegalArgumentException(EXCEPTIONMSG_CLUSTER_DOES_NOT_EXIST + Cluster.fullName(clusterName)); } try { String path = PathUtil.clusterBackupSchedulePath(clusterName); try { ClusterBackupSchedule data = mapper.readValue(zk.getData(path, null), ClusterBackupSchedule.class); if (!data.existBackupJob(arg.getBackup_id())) { data.addBackupSchedule(arg); } else { data.updateBackupSchedule(arg); } zk.setData(path, mapper.writeValueAsBytes(data), -1); } catch (KeeperException.NoNodeException e) { // Create znode for BACKUP_PROP ClusterBackupSchedule data = new ClusterBackupSchedule(); data.addBackupSchedule(arg); zk.createPersistentZNode(path, mapper.writeValueAsBytes(data)); } } catch (ConfMasterException e) { String logMsg = "-ERR " + e.getMessage(); Logger.error("Set appdate fail. {} {}", clusterName, arg, e); return logMsg; } return S2C_OK; }
From source file:com.yahoo.pulsar.discovery.service.BrokerDiscoveryProvider.java
License:Apache License
protected static void checkAuthorization(DiscoveryService service, DestinationName destination, String role) throws IllegalAccessException { if (!service.getConfiguration().isAuthorizationEnabled() || service.getConfiguration().getSuperUserRoles().contains(role)) { // No enforcing of authorization policies return;//from w ww. j ava 2s .c om } // get zk policy manager if (!service.getAuthorizationManager().canLookup(destination, role)) { LOG.warn("[{}] Role {} is not allowed to lookup topic", destination, role); // check namespace authorization PropertyAdmin propertyAdmin; try { propertyAdmin = service.getConfigurationCacheService().propertiesCache() .get(path("policies", destination.getProperty())) .orElseThrow(() -> new IllegalAccessException("Property does not exist")); } catch (KeeperException.NoNodeException e) { LOG.warn("Failed to get property admin data for non existing property {}", destination.getProperty()); throw new IllegalAccessException("Property does not exist"); } catch (Exception e) { LOG.error("Failed to get property admin data for property"); throw new IllegalAccessException(String.format("Failed to get property %s admin data due to %s", destination.getProperty(), e.getMessage())); } if (!propertyAdmin.getAdminRoles().contains(role)) { throw new IllegalAccessException( "Don't have permission to administrate resources on this property"); } } if (LOG.isDebugEnabled()) { LOG.debug("Successfully authorized {} on property {}", role, destination.getProperty()); } }
From source file:io.flood.registry.zk.ZookeeperRegistry.java
License:Apache License
public void delete(String path) { try {//from w w w.j a va 2 s.c o m client.delete().forPath(path); } catch (KeeperException.NoNodeException e) { } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:io.flood.registry.zk.ZookeeperRegistry.java
License:Apache License
public List<String> getChildren(String path) { try {//w w w . j av a 2s . c om return client.getChildren().forPath(path); } catch (KeeperException.NoNodeException e) { return null; } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:org.apache.curator.framework.recipes.locks.InterProcessExpiringSemaphore.java
License:Apache License
/** * @param nodeName/*from w ww . j a va2 s .c o m*/ * @param children * @return The duration until next expiring lease, or a negative number if * none of the leases are expiring (expiration disabled, all leases * purged, etc...) * @throws Exception */ protected long purgeExpiredLeases(String nodeName, List<String> children) throws Exception { int oldestNonExpiredChildAge = Integer.MIN_VALUE; int timeToLiveMs = getLeaseTimeToLive(); if (timeToLiveMs < 0) { return oldestNonExpiredChildAge; } // Inter-Process safe way of getting current ZK time (avoid // using System.currentTimeMillis() as it may not be in sync // across all instances) long currentTime = currentTimeProvider.getCurrentTime(); // expire all leases that have expired for (String child : children) { // do not expire self if (nodeName.equals(child)) { continue; } String childPath = ZKPaths.makePath(leasesPath, child); try { // get the data for the given child node to see if it has expired long createdTime = getCreatedTime(childPath); // compute the age of the node long nodeAge = currentTime - createdTime; log.trace("Lease {} is {} ms old", childPath, nodeAge); if (nodeAge > timeToLiveMs) { log.warn("Lease {} expired (age: {} ms), evicting...", childPath, nodeAge); client.delete().forPath(childPath); log.warn("Lease {} purged", childPath); } else { if (oldestNonExpiredChildAge < nodeAge) { oldestNonExpiredChildAge = (int) nodeAge; } } } catch (KeeperException.NoNodeException ex) { log.trace("Attempting to purge {}, but node is already removed", childPath); } catch (Exception ex) { log.warn("Unable to determine if child node {} is expired due to {}", childPath, ex.getMessage()); } } // if not not all child nodes expired, figure out how long until next node is due to expire int timeToNextExpiredChild = (timeToLiveMs - oldestNonExpiredChildAge); return timeToNextExpiredChild; }
From source file:org.apache.pulsar.discovery.service.BrokerDiscoveryProvider.java
License:Apache License
protected static void checkAuthorization(DiscoveryService service, DestinationName destination, String role) throws Exception { if (!service.getConfiguration().isAuthorizationEnabled() || service.getConfiguration().getSuperUserRoles().contains(role)) { // No enforcing of authorization policies return;/* w w w . ja v a2 s . c om*/ } // get zk policy manager if (!service.getAuthorizationManager().canLookup(destination, role)) { LOG.warn("[{}] Role {} is not allowed to lookup topic", destination, role); // check namespace authorization PropertyAdmin propertyAdmin; try { propertyAdmin = service.getConfigurationCacheService().propertiesCache() .get(path("policies", destination.getProperty())) .orElseThrow(() -> new IllegalAccessException("Property does not exist")); } catch (KeeperException.NoNodeException e) { LOG.warn("Failed to get property admin data for non existing property {}", destination.getProperty()); throw new IllegalAccessException("Property does not exist"); } catch (Exception e) { LOG.error("Failed to get property admin data for property"); throw new IllegalAccessException(String.format("Failed to get property %s admin data due to %s", destination.getProperty(), e.getMessage())); } if (!propertyAdmin.getAdminRoles().contains(role)) { throw new IllegalAccessException( "Don't have permission to administrate resources on this property"); } } if (LOG.isDebugEnabled()) { LOG.debug("Successfully authorized {} on property {}", role, destination.getProperty()); } }
From source file:org.apache.pulsar.proxy.server.BrokerDiscoveryProvider.java
License:Apache License
protected static void checkAuthorization(ProxyService service, TopicName topicName, String role, AuthenticationDataSource authenticationData) throws Exception { if (!service.getConfiguration().isAuthorizationEnabled() || service.getConfiguration().getSuperUserRoles().contains(role)) { // No enforcing of authorization policies return;/*w w w . j ava 2s.c om*/ } // get zk policy manager if (!service.getAuthorizationService().canLookup(topicName, role, authenticationData)) { LOG.warn("[{}] Role {} is not allowed to lookup topic", topicName, role); // check namespace authorization TenantInfo tenantInfo; try { tenantInfo = service.getConfigurationCacheService().propertiesCache() .get(path(POLICIES, topicName.getTenant())) .orElseThrow(() -> new IllegalAccessException("Property does not exist")); } catch (KeeperException.NoNodeException e) { LOG.warn("Failed to get property admin data for non existing property {}", topicName.getTenant()); throw new IllegalAccessException("Property does not exist"); } catch (Exception e) { LOG.error("Failed to get property admin data for property"); throw new IllegalAccessException(String.format("Failed to get property %s admin data due to %s", topicName.getTenant(), e.getMessage())); } if (!tenantInfo.getAdminRoles().contains(role)) { throw new IllegalAccessException("Don't have permission to administrate resources on this tenant"); } } if (LOG.isDebugEnabled()) { LOG.debug("Successfully authorized {} on property {}", role, topicName.getTenant()); } }
From source file:org.trustedanalytics.auth.gateway.zookeeper.client.KerberosfulZookeeperClient.java
License:Apache License
@Override public void deleteZnode(String znodePath) throws Exception { try {//from w ww . j ava 2 s . c om curatorClient.delete().forPath(pathOps.makePath(znodePath)); } catch (KeeperException.NoNodeException e) { LOGGER.info("Caught: '" + e.getMessage() + "' while deleting node. Nothing to do.", e); } }