use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class BaseColumnarLongsBenchmark method checkRowSanity.
static void checkRowSanity(Map<String, ColumnarLongs> encoders, List<String> encodings, int row) {
if (encodings.size() > 1) {
for (int i = 0; i < encodings.size() - 1; i++) {
String currentKey = encodings.get(i);
String nextKey = encodings.get(i + 1);
ColumnarLongs current = encoders.get(currentKey);
ColumnarLongs next = encoders.get(nextKey);
long vCurrent = current.get(row);
long vNext = next.get(row);
if (vCurrent != vNext) {
throw new RE("values do not match at row %s - %s:%s %s:%s", row, currentKey, vCurrent, nextKey, vNext);
}
}
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class DefaultK8sApiClient method listPods.
@Override
public DiscoveryDruidNodeList listPods(String podNamespace, String labelSelector, NodeRole nodeRole) {
try {
V1PodList podList = coreV1Api.listNamespacedPod(podNamespace, null, null, null, null, labelSelector, 0, null, null, null);
Preconditions.checkState(podList != null, "WTH: NULL podList");
Map<String, DiscoveryDruidNode> allNodes = new HashMap();
for (V1Pod podDef : podList.getItems()) {
DiscoveryDruidNode node = getDiscoveryDruidNodeFromPodDef(nodeRole, podDef);
allNodes.put(node.getDruidNode().getHostAndPortToUse(), node);
}
return new DiscoveryDruidNodeList(podList.getMetadata().getResourceVersion(), allNodes);
} catch (ApiException ex) {
throw new RE(ex, "Expection in listing pods, code[%d] and error[%s].", ex.getCode(), ex.getResponseBody());
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class K8sDruidNodeAnnouncer method announce.
@Override
public void announce(DiscoveryDruidNode discoveryDruidNode) {
LOGGER.info("Announcing DiscoveryDruidNode[%s]", discoveryDruidNode);
String roleAnnouncementLabel = getRoleAnnouncementLabel(discoveryDruidNode.getNodeRole());
String idAnnouncementLabel = getIdHashAnnouncementLabel();
String clusterIdentifierAnnouncementLabel = getClusterIdentifierAnnouncementLabel();
String infoAnnotation = getInfoAnnotation(discoveryDruidNode.getNodeRole());
try {
List<Map<String, Object>> patches = new ArrayList<>();
// Note: We assume here that at least one label and annotation exists on the pod already, so that
// paths where labels/annotations are created, pre-exist.
// See https://github.com/kubernetes-sigs/kustomize/issues/2986 , we can add workaround of getting pod spec,
// checking if label/annotation path exists and create if not, however that could lead to race conditions
// so assuming the existence for now.
patches.add(createPatchObj(OP_ADD, getPodDefLabelPath(roleAnnouncementLabel), ANNOUNCEMENT_DONE));
patches.add(createPatchObj(OP_ADD, getPodDefLabelPath(idAnnouncementLabel), hashEncodeStringForLabelValue(discoveryDruidNode.getDruidNode().getHostAndPortToUse())));
patches.add(createPatchObj(OP_ADD, getPodDefLabelPath(clusterIdentifierAnnouncementLabel), discoveryConfig.getClusterIdentifier()));
patches.add(createPatchObj(OP_ADD, getPodDefAnnocationPath(infoAnnotation), jsonMapper.writeValueAsString(discoveryDruidNode)));
// Creating patch string outside of retry block to not retry json serialization failures
String jsonPatchStr = jsonMapper.writeValueAsString(patches);
LOGGER.info("Json Patch For Node Announcement: [%s]", jsonPatchStr);
RetryUtils.retry(() -> {
k8sApiClient.patchPod(podInfo.getPodName(), podInfo.getPodNamespace(), jsonPatchStr);
return "na";
}, (throwable) -> true, 3);
LOGGER.info("Announced DiscoveryDruidNode[%s]", discoveryDruidNode);
} catch (Exception ex) {
throw new RE(ex, "Failed to announce DiscoveryDruidNode[%s]", discoveryDruidNode);
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class DefaultK8sLeaderElectorFactory method create.
@Override
public K8sLeaderElector create(String candidateId, String namespace, String lockResourceName) {
Lock lock = createLock(candidateId, namespace, lockResourceName, realK8sClient);
LeaderElectionConfig leaderElectionConfig = new LeaderElectionConfig(lock, Duration.ofMillis(discoveryConfig.getLeaseDuration().getMillis()), Duration.ofMillis(discoveryConfig.getRenewDeadline().getMillis()), Duration.ofMillis(discoveryConfig.getRetryPeriod().getMillis()));
LeaderElector leaderElector = new LeaderElector(leaderElectionConfig);
return new K8sLeaderElector() {
@Override
public String getCurrentLeader() {
try {
return lock.get().getHolderIdentity();
} catch (ApiException ex) {
throw new RE(ex, "Failed to get current leader for [%s]", lockResourceName);
}
}
@Override
public void run(Runnable startLeadingHook, Runnable stopLeadingHook) {
leaderElector.run(startLeadingHook, stopLeadingHook);
}
};
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class S3DataSegmentPuller method getVersion.
/**
* Returns the "version" (aka last modified timestamp) of the URI
*
* @param uri The URI to check the last timestamp
* @return The time in ms of the last modification of the URI in String format
* @throws IOException
*/
@Override
public String getVersion(URI uri) throws IOException {
try {
final CloudObjectLocation coords = new CloudObjectLocation(S3Utils.checkURI(uri));
final S3ObjectSummary objectSummary = S3Utils.getSingleObjectSummary(s3Client, coords.getBucket(), coords.getPath());
return StringUtils.format("%d", objectSummary.getLastModified().getTime());
} catch (AmazonClientException e) {
if (AWSClientUtil.isClientExceptionRecoverable(e)) {
// The recoverable logic is always true for IOException, so we want to only pass IOException if it is recoverable
throw new IOE(e, "Could not fetch last modified timestamp from URI [%s]", uri);
} else {
throw new RE(e, "Error fetching last modified timestamp from URI [%s]", uri);
}
}
}
Aggregations