This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.javabridge;
020
021import org.apache.reef.annotations.audience.Interop;
022import org.apache.reef.annotations.audience.Private;
023import org.apache.reef.driver.task.FailedTask;
024
025import java.nio.charset.StandardCharsets;
026import java.util.logging.Level;
027import java.util.logging.Logger;
028
029/**
030 * The Java-CLR bridge object for {@link org.apache.reef.driver.task.FailedTask}.
031 */
032@Private
033@Interop(
034    CppFiles = { "Clr2JavaImpl.h", "FailedTaskClr2Java.cpp" },
035    CsFiles = { "IFailedTaskClr2Java.cs", "FailedTask.cs" })
036public final class FailedTaskBridge extends NativeBridge {
037  private static final Logger LOG = Logger.getLogger(FailedTaskBridge.class.getName());
038
039  private FailedTask jfailedTask;
040  private ActiveContextBridge jactiveContext;
041
042  public FailedTaskBridge(final FailedTask failedTask, final ActiveContextBridgeFactory factory) {
043    this.jfailedTask = failedTask;
044    if (failedTask.getActiveContext().isPresent()) {
045      this.jactiveContext = factory.getActiveContextBridge(failedTask.getActiveContext().get());
046    } else {
047      this.jactiveContext = null;
048    }
049  }
050
051  public ActiveContextBridge getActiveContext() {
052    return jactiveContext;
053  }
054
055  public String getFailedTaskString() {
056    final String description = jfailedTask.getDescription().isPresent() ?
057        jfailedTask.getDescription().get().replace("=", "").replace(",", "") : "";
058    final String cause = jfailedTask.getReason().isPresent() ?
059        jfailedTask.getReason().get().toString().replace("=", "").replace(",", "") : "";
060    final String data = jfailedTask.getData().isPresent() ?
061        new String(jfailedTask.getData().get(), StandardCharsets.UTF_8).replace("=", "").replace(",", "") : "";
062
063    // TODO[JIRA REEF-796]: deserialize/serialize with proper Avro schema
064    final String poorSerializedString = "Identifier=" + jfailedTask.getId().replace("=", "").replace(",", "")
065        + ", Message=" + jfailedTask.getMessage().replace("=", "").replace(",", "")
066        + ", Description=" + description
067        + ", Cause=" + cause
068        + ", Data=" + data;
069
070    LOG.log(Level.INFO, "serialized failed task " + poorSerializedString);
071    return poorSerializedString;
072  }
073
074  @Override
075  public void close() {
076  }
077}
078