public synchronized void setInstanceDescriptor(UbaCoordinate ubaCoordinate, InstanceDescriptor id) throws Exception { InstanceDescriptor got = instanceDescriptor.get(); if (got != null && !got.equals(id)) { instancePath.writeInstanceDescriptor(ubaCoordinate, id); ensureCerts(id); startupId.incrementAndGet(); unexpectedRestartTimestamp.set(-1); redeploy.set(true); LOG.info("Instance changed from " + got + " to " + id); } else if (!instancePath.script("status").exists()) { startupId.incrementAndGet(); unexpectedRestartTimestamp.set(-1); redeploy.set(true); LOG.info("Missing status script from " + got + " to " + id); } if (!redeploy.get()) { LOG.debug("Service:" + instancePath.toHumanReadableName() + " has NOT changed."); } else { instanceDescriptor.set(id); } if (id.restartTimestampGMTMillis > lastRestart.get()) { restartAtTimestamp.set(id.restartTimestampGMTMillis); } }
public Nanny( PasswordStore passwordStore, UpenaClient upenaClient, RepositoryProvider repositoryProvider, InstanceDescriptor instanceDescriptor, InstancePath instancePath, DeployableValidator deployableValidator, DeployLog deployLog, HealthLog healthLog, DeployableScriptInvoker invokeScript, UbaLog ubaLog, Cache<String, Boolean> haveRunConfigExtractionCache) { this.passwordStore = passwordStore; this.upenaClient = upenaClient; this.repositoryProvider = repositoryProvider; this.instanceDescriptor = new AtomicReference<>(instanceDescriptor); this.instancePath = instancePath; this.deployableValidator = deployableValidator; this.deployLog = deployLog; this.healthLog = healthLog; this.invokeScript = invokeScript; this.ubaLog = ubaLog; linkedBlockingQueue = new LinkedBlockingQueue<>(10); threadPoolExecutor = new ThreadPoolExecutor(1, 1, 1000, TimeUnit.MILLISECONDS, linkedBlockingQueue); boolean exists = instancePath.deployLog().exists(); LOG.info("Stats script for {} exists == {}", instanceDescriptor, exists); redeploy = new AtomicBoolean(!exists); destroyed = new AtomicBoolean(false); this.haveRunConfigExtractionCache = haveRunConfigExtractionCache; }
String invalidateRouting(String tenantId) { try { LOG.info("invalidating tenant routing for tenatId:" + tenantId + " on " + this); StringBuilder curl = new StringBuilder(); curl.append("localhost:"); curl.append(instanceDescriptor.get().ports.get("manage")); curl.append("/tenant/routing/invalidate?"); curl.append("tenantId=").append(tenantId).append('&'); curl.append("connectToServiceId=*").append('&'); curl.append("portName=*"); String response = Curl.create().curl(curl.toString()); LOG.info(response); return response; } catch (IOException x) { LOG.warn("failed to invalidate tenant routing for tenantId:" + tenantId + " on " + this); return "failed to invalidate tenant routing for tenantId:" + tenantId + " on " + this; } }
public void commitRows(PartitionName partitionName, List<Row> rows) throws Exception { LOG.info("Received from partition:{} rows:{}", partitionName, rows.size()); PartitionClient client = partitionClientProvider.getPartition(partitionName); Consistency consistency = consistencyCache.computeIfAbsent( partitionName, partitionName1 -> { try { RingPartitionProperties properties = partitionClientProvider.getProperties(partitionName1); return properties != null ? properties.partitionProperties.consistency : null; } catch (Exception e) { LOG.error("Failed to get properties for partition:{}", partitionName1); return null; } }); if (consistency == null) { throw new RuntimeException("Missing consistency for partition: " + partitionName); } PeekingIterator<Row> iter = Iterators.peekingIterator(rows.iterator()); while (iter.hasNext()) { byte[] prefix = iter.peek().prefix; client.commit( consistency, prefix, commitKeyValueStream -> { while (iter.hasNext()) { byte[] peek = iter.peek().prefix; if ((prefix == null && peek == null) || (prefix != null && peek != null && Arrays.equals(prefix, peek))) { Row row = iter.next(); commitKeyValueStream.commit( row.key, row.value, row.valueTimestamp, row.valueTombstoned); } else { break; } } return true; }, additionalSolverAfterNMillis, abandonSolutionAfterNMillis, Optional.empty()); } }