Search in sources :

Example 26 with RE

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);
            }
        }
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) ColumnarLongs(org.apache.druid.segment.data.ColumnarLongs)

Example 27 with RE

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());
    }
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) RE(org.apache.druid.java.util.common.RE) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) HashMap(java.util.HashMap) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiException(io.kubernetes.client.openapi.ApiException)

Example 28 with RE

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);
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 29 with RE

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);
        }
    };
}
Also used : RE(org.apache.druid.java.util.common.RE) LeaderElector(io.kubernetes.client.extended.leaderelection.LeaderElector) LeaderElectionConfig(io.kubernetes.client.extended.leaderelection.LeaderElectionConfig) ConfigMapLock(io.kubernetes.client.extended.leaderelection.resourcelock.ConfigMapLock) Lock(io.kubernetes.client.extended.leaderelection.Lock) ApiException(io.kubernetes.client.openapi.ApiException)

Example 30 with RE

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);
        }
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) CloudObjectLocation(org.apache.druid.data.input.impl.CloudObjectLocation) AmazonClientException(com.amazonaws.AmazonClientException) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOE(org.apache.druid.java.util.common.IOE)

Aggregations

RE (org.apache.druid.java.util.common.RE)46 IOException (java.io.IOException)11 Request (org.apache.druid.java.util.http.client.Request)10 URL (java.net.URL)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 ExecutionException (java.util.concurrent.ExecutionException)5 ISE (org.apache.druid.java.util.common.ISE)5 Map (java.util.Map)4 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 HashMap (java.util.HashMap)3 DataSegment (org.apache.druid.timeline.DataSegment)3 OSSException (com.aliyun.oss.OSSException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ApiException (io.kubernetes.client.openapi.ApiException)2 File (java.io.File)2