abhishekagarwal87 commented on code in PR #14887: URL: https://github.com/apache/druid/pull/14887#discussion_r1339808899
########## processing/src/main/java/org/apache/druid/error/InternalError.java: ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.error; + +public class InternalError extends DruidException.Failure Review Comment: how about InternalServerError? ########## processing/src/main/java/org/apache/druid/error/InternalError.java: ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.error; + +public class InternalError extends DruidException.Failure +{ + + public static DruidException exception() + { + return exception("Internal Error"); + } + + public static DruidException exception(String msg, Object... args) + { + return exception(null, msg, args); + } + + public static DruidException exception(Throwable t, String msg, Object... args) + { + return DruidException.fromFailure(new InternalError(t, msg, args)); + } + + private final Throwable t; + private final String msg; + private final Object[] args; + + private InternalError( + Throwable t, + String msg, + Object... args + ) + { + super("canceled"); + this.t = t; + this.msg = msg; + this.args = args; + } + + @Override + public DruidException makeException(DruidException.DruidExceptionBuilder bob) + { + bob = bob.forPersona(DruidException.Persona.OPERATOR) + .ofCategory(DruidException.Category.CANCELED); Review Comment: it should be runtime_failure category. ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/taskadapter/K8sTaskAdapter.java: ########## @@ -132,11 +141,36 @@ public Task toTask(Job from) throws IOException Optional<EnvVar> taskJson = envVars.stream().filter(x -> "TASK_JSON".equals(x.getName())).findFirst(); String contents = taskJson.map(envVar -> taskJson.get().getValue()).orElse(null); if (contents == null) { - throw new IOException("No TASK_JSON environment variable found in pod: " + from.getMetadata().getName()); + log.info("No TASK_JSON environment variable found in pod: %s. Trying to load task payload from deep storage.", from.getMetadata().getName()); + return toTaskUsingDeepStorage(from); } return mapper.readValue(Base64Compression.decompressBase64(contents), Task.class); } + private Task toTaskUsingDeepStorage(Job from) throws IOException + { + com.google.common.base.Optional<InputStream> taskBody = taskLogs.streamTaskPayload(getTaskId(from).getOriginalTaskId()); + if (!taskBody.isPresent()) { + throw InternalError.exception("Could not load task payload for job [%s]", from.getMetadata().getName()); Review Comment: is there an action you can associate with this error message? Like should they verify that overlord is successfully uploading task jsons to deep storage. ########## processing/src/main/java/org/apache/druid/error/InternalError.java: ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.error; + +public class InternalError extends DruidException.Failure +{ + + public static DruidException exception() + { + return exception("Internal Error"); + } + + public static DruidException exception(String msg, Object... args) + { + return exception(null, msg, args); + } + + public static DruidException exception(Throwable t, String msg, Object... args) + { + return DruidException.fromFailure(new InternalError(t, msg, args)); + } + + private final Throwable t; + private final String msg; + private final Object[] args; + + private InternalError( + Throwable t, + String msg, + Object... args + ) + { + super("canceled"); Review Comment: Why canceled? Instead, you can force the caller to pass on an error code. ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/taskadapter/K8sTaskAdapter.java: ########## @@ -132,11 +141,36 @@ public Task toTask(Job from) throws IOException Optional<EnvVar> taskJson = envVars.stream().filter(x -> "TASK_JSON".equals(x.getName())).findFirst(); String contents = taskJson.map(envVar -> taskJson.get().getValue()).orElse(null); if (contents == null) { - throw new IOException("No TASK_JSON environment variable found in pod: " + from.getMetadata().getName()); + log.info("No TASK_JSON environment variable found in pod: %s. Trying to load task payload from deep storage.", from.getMetadata().getName()); + return toTaskUsingDeepStorage(from); } return mapper.readValue(Base64Compression.decompressBase64(contents), Task.class); } + private Task toTaskUsingDeepStorage(Job from) throws IOException + { + com.google.common.base.Optional<InputStream> taskBody = taskLogs.streamTaskPayload(getTaskId(from).getOriginalTaskId()); + if (!taskBody.isPresent()) { + throw InternalError.exception("Could not load task payload for job [%s]", from.getMetadata().getName()); + } + String task = IOUtils.toString(taskBody.get(), Charset.defaultCharset()); + return mapper.readValue(task, Task.class); + } + + @Override + public K8sTaskId getTaskId(Job from) throws IOException + { + Map<String, String> annotations = from.getSpec().getTemplate().getMetadata().getAnnotations(); + if (annotations == null) { + throw new IOE("No annotations found on pod spec for job [%s]", from.getMetadata().getName()); Review Comment: can this be replaced with DruidException.defensive()? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
