Example usage for java.io IOException getLocalizedMessage

List of usage examples for java.io IOException getLocalizedMessage

Introduction

In this page you can find the example usage for java.io IOException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:fr.treeptik.cloudunit.docker.DockerContainerJSON.java

public DockerContainer findOne(String name, String hostIp) throws DockerJSONException {
    URI uri = null;/*from  w w w. j  a v a2  s  .c  o  m*/
    DockerContainer dockerContainer = new DockerContainer();
    try {
        uri = new URIBuilder().setScheme(dockerEndpointMode).setHost(hostIp)
                .setPath("/containers/" + name + "/json").build();
        JsonResponse jsonResponse = null;

        // Docker error management

        try {

            jsonResponse = client.sendGet(uri);

            switch (jsonResponse.getStatus()) {
            case 404:
                throw new ErrorDockerJSONException("docker : no such container");
            case 500:
                throw new ErrorDockerJSONException("docker : server error");
            }

        } catch (IOException e) {
            throw new FatalDockerJSONException(e.getLocalizedMessage());
        }

        // Init maps for volumes and ports

        Map<String, String> ports = new HashMap<>();
        Map<String, String> volumes = new HashMap<>();

        // SubString to remove the "/"
        String response = jsonResponse.getMessage();

        dockerContainer.setName(parser(response).get("Name").toString().substring(1));
        dockerContainer.setId((String) parser(response).get("Id").toString());

        Long memorySwap = (Long) parser(parser(response).get("Config").toString()).get("MemorySwap");
        Long memory = (Long) parser(parser(response).get("Config").toString()).get("Memory");
        dockerContainer.setMemorySwap(memorySwap);
        dockerContainer.setMemory(memory);
        dockerContainer.setImage((String) parser(parser(response).get("Config").toString()).get("Image"));

        if (parser(parser(response).get("HostConfig").toString()).get("VolumesFrom") != null) {
            dockerContainer.setVolumesFrom(
                    getList(parser(parser(response).get("HostConfig").toString()), "VolumesFrom"));
        }

        dockerContainer
                .setIp((String) parser(parser(response).get("NetworkSettings").toString()).get("IPAddress"));

        if (parser(parser(response).get("NetworkSettings").toString()).get("Ports") != null) {
            for (Object port : parser(
                    parser(parser(response).get("NetworkSettings").toString()).get("Ports").toString())
                            .keySet()) {

                if (!Arrays.asList(fixedPort).contains(port.toString())) {
                    Object forwardedPort = (Object) getObjectList(parser(
                            parser(parser(response).get("NetworkSettings").toString()).get("Ports").toString()),
                            port.toString()).get(0);
                    ports.put(port.toString(), parser(forwardedPort.toString()).get("HostPort").toString());
                }
            }
        }

        if (parser(response).get("Volumes") != null) {
            for (Object volume : parser(parser(response).get("Volumes").toString()).keySet()) {

                volumes.put(volume.toString(),
                        parser(parser(response).get("Volumes").toString()).get(volume.toString()).toString());

            }
        }

        dockerContainer.setVolumes(volumes);

        logger.debug("Volumes : " + volumes);

        dockerContainer.setPorts(ports);
        dockerContainer.setCmd(getList(parser(parser(response).get("Config").toString()), "Cmd"));
        if (parser(parser(response).get("State").toString()).get("Running").toString().equals("true")) {
            dockerContainer.setState("Running");
        }

        if (parser(parser(response).get("State").toString()).get("Running").toString().equals("false")
                && parser(parser(response).get("State").toString()).get("Paused").toString().equals("false")) {
            dockerContainer.setState("Paused");
        }

        if (parser(parser(response).get("State").toString()).get("Paused").toString().equals("true")) {
            dockerContainer.setState("Paused");
        }

    } catch (NumberFormatException | URISyntaxException | ParseException e) {
        StringBuilder msgError = new StringBuilder(256);
        msgError.append(name).append(",hostIP=").append(hostIp).append(",uri=").append(uri);
        logger.error("" + msgError, e);
        throw new FatalDockerJSONException("docker : error fatal");
    }

    return dockerContainer;
}

From source file:com.datascience.gal.service.Service.java

/**
 * add a gold label to the model//from   w  ww  . j ava  2 s.  c o m
 * 
 * @return a simple success message
 */
@POST
@Path("loadGoldLabel")
@Produces(MediaType.APPLICATION_JSON)
public Response loadGoldLabel(@FormParam("data") String data, @FormParam("id") String idstr) {
    CorrectLabel label;

    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {

        label = JSONUtils.gson.fromJson(data, JSONUtils.correctLabelType);
        setup(context);
        DawidSkene ds = dscache.getDawidSkene(id);
        ds.addCorrectLabel(label);
        dscache.insertDawidSkene(ds);
        String message = "adding gold label: " + label.toString();
        logger.info(message);
        return Response.ok(message).build();
    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {

        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();
}

From source file:com.datascience.gal.service.Service.java

@GET
@Path("printWorkerSummary")
@Produces(MediaType.APPLICATION_JSON)/*from w ww. j a  va  2s . c o  m*/
public Response printWorkerSummary(@QueryParam("verbose") String verbose, @QueryParam("id") String idstr) {
    String output;

    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {
        setup(context);
        DawidSkene ds = dscache.getDawidSkene(id);

        boolean verb = null == verbose ? false : true;
        output = ds.printAllWorkerScores(verb);

        String message = "returning request for worker summary";
        logger.info(message);

        return Response.ok(output).build();

    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();
}

From source file:com.datascience.gal.service.Service.java

@GET
@Path("objectProbs")
@Produces(MediaType.APPLICATION_JSON)/*from   www.  java 2 s.com*/
public Response objectProbs(@QueryParam("object") String object, @QueryParam("entropy") String ent,
        @QueryParam("id") String idstr) {
    Map<String, Double> out;

    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {
        setup(context);
        DawidSkene ds = dscache.getDawidSkene(id);

        double entropy = null == ent ? 0. : Double.parseDouble(ent);
        out = ds.objectClassProbabilities(object, entropy);

        String message = "returning request for object class probs";
        logger.info(message);
        return Response.ok(JSONUtils.gson.toJson(out)).build();

    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();
}

From source file:fr.treeptik.cloudunit.docker.DockerContainerJSON.java

public DockerContainer findOneWithImageID(String name, String hostIp) throws DockerJSONException {
    URI uri = null;/*from w w  w.j  a  va2  s .c o m*/
    DockerContainer dockerContainer = new DockerContainer();
    try {
        uri = new URIBuilder().setScheme(dockerEndpointMode).setHost(hostIp)
                .setPath("/containers/" + name + "/json").build();
        JsonResponse jsonResponse = null;

        // Docker error management

        try {

            jsonResponse = client.sendGet(uri);

            switch (jsonResponse.getStatus()) {
            case 404:
                throw new ErrorDockerJSONException("docker : no such container");
            case 500:
                throw new ErrorDockerJSONException("docker : server error");
            }

        } catch (IOException e) {
            throw new FatalDockerJSONException(e.getLocalizedMessage());
        }

        // Init maps for volumes and ports

        Map<String, String> ports = new HashMap<>();
        Map<String, String> volumes = new HashMap<>();

        // SubString to remove the "/"
        String response = jsonResponse.getMessage();

        dockerContainer.setImageID((String) parser(response).get("Image").toString());
        dockerContainer.setName(parser(response).get("Name").toString().substring(1));
        dockerContainer.setId((String) parser(response).get("Id").toString());

        Long memorySwap = (Long) parser(parser(response).get("Config").toString()).get("MemorySwap");
        Long memory = (Long) parser(parser(response).get("Config").toString()).get("Memory");
        dockerContainer.setMemorySwap(memorySwap);
        dockerContainer.setMemory(memory);
        dockerContainer.setImage((String) parser(parser(response).get("Config").toString()).get("Image"));

        if (parser(parser(response).get("HostConfig").toString()).get("VolumesFrom") != null) {
            dockerContainer.setVolumesFrom(
                    getList(parser(parser(response).get("HostConfig").toString()), "VolumesFrom"));
        }

        dockerContainer
                .setIp((String) parser(parser(response).get("NetworkSettings").toString()).get("IPAddress"));

        if (parser(parser(response).get("NetworkSettings").toString()).get("Ports") != null) {
            for (Object port : parser(
                    parser(parser(response).get("NetworkSettings").toString()).get("Ports").toString())
                            .keySet()) {

                if (!Arrays.asList(fixedPort).contains(port.toString())) {
                    Object forwardedPort = (Object) getObjectList(parser(
                            parser(parser(response).get("NetworkSettings").toString()).get("Ports").toString()),
                            port.toString()).get(0);
                    ports.put(port.toString(), parser(forwardedPort.toString()).get("HostPort").toString());
                }
            }
        }

        if (parser(response).get("Volumes") != null) {
            for (Object volume : parser(parser(response).get("Volumes").toString()).keySet()) {

                volumes.put(volume.toString(),
                        parser(parser(response).get("Volumes").toString()).get(volume.toString()).toString());

            }
        }

        dockerContainer.setVolumes(volumes);

        logger.debug("Volumes : " + volumes);

        dockerContainer.setPorts(ports);
        dockerContainer.setCmd(getList(parser(parser(response).get("Config").toString()), "Cmd"));
        if (parser(parser(response).get("State").toString()).get("Running").toString().equals("true")) {
            dockerContainer.setState("Running");
        }

        if (parser(parser(response).get("State").toString()).get("Running").toString().equals("false")
                && parser(parser(response).get("State").toString()).get("Paused").toString().equals("false")) {
            dockerContainer.setState("Paused");
        }

        if (parser(parser(response).get("State").toString()).get("Paused").toString().equals("true")) {
            dockerContainer.setState("Paused");
        }

    } catch (NumberFormatException | URISyntaxException | ParseException e) {
        StringBuilder msgError = new StringBuilder(256);
        msgError.append(name).append(",hostIP=").append(hostIp).append(",uri=").append(uri);
        logger.error("" + msgError, e);
        throw new FatalDockerJSONException("docker : error fatal");
    }

    return dockerContainer;
}

From source file:com.datascience.gal.service.Service.java

/**
 * add a worker-assigned label to the model
 * /*from   w ww. ja  v  a2 s  . c  o  m*/
 * @return a simple success message
 */
@POST
@Path("loadWorkerAssignedLabel")
@Produces(MediaType.APPLICATION_JSON)
public Response loadWorkerAssignedLabel(@FormParam("data") String data, @FormParam("id") String idstr) {
    AssignedLabel label;

    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {
        setup(context);
        label = JSONUtils.gson.fromJson(data, JSONUtils.assignedLabelType);

        DawidSkene ds = dscache.getDawidSkene(id);
        ds.addAssignedLabel(label);
        dscache.insertDawidSkene(ds);

        String message = "adding " + label.toString();
        logger.info(message);
        return Response.ok(message).build();
    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();

}

From source file:com.datascience.gal.service.Service.java

/**
 * Loads a json set of misclassification cost objects
 * //from  ww w . j a  v a  2s . c om
 * @return a simple success message
 */
@POST
@Path("loadCosts")
@Produces(MediaType.APPLICATION_JSON)
public Response loadMisclassificationCosts(@FormParam("costs") String data, @FormParam("id") String idstr) {
    Collection<MisclassificationCost> costs;
    if (null == data || data.length() < 3) {
        String message = "invalid input. requires json-ified collection of misclassification cost objects";
        logger.error(message);
        return Response.status(500).build();
    }
    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {
        setup(context);
        costs = JSONUtils.gson.fromJson(data, JSONUtils.misclassificationCostSetType);
        DawidSkene ds = dscache.getDawidSkene(id);
        ds.addMisclassificationCosts(costs);
        dscache.insertDawidSkene(ds);
        String message = "adding " + costs.size() + " new misclassification costs";
        logger.info(message);
        return Response.ok(message).build();

    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();
}

From source file:com.datascience.gal.service.Service.java

/**
 * computes majority votes for object//  w  w  w.ja v  a  2s  . co  m
 * 
 * @return map of majority votes
 */
@GET
@Path("majorityVote")
@Produces(MediaType.APPLICATION_JSON)
public Response majorityVote(@QueryParam("id") String idstr, @QueryParam("objectName") String objectName) {

    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {
        setup(context);
        DawidSkene ds = dscache.getDawidSkene(id);
        String votes = ds.getMajorityVote(objectName);

        if (votes == null) {
            logger.warn("got a null majority vote for object: " + objectName);
            Response.status(500).build();
        }

        String message = "computing majority votes for " + objectName;
        logger.info(message);
        return Response.ok(JSONUtils.gson.toJson(votes)).build();

    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {

        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();
}

From source file:com.datascience.gal.service.Service.java

/**
 * computes majority votes for objects// w w  w . ja  v  a 2s  .  c om
 * 
 * @return map of majority votes
 */
@POST
@Path("majorityVotes")
@Produces(MediaType.APPLICATION_JSON)
public Response majorityVotes(@FormParam("id") String idstr, @FormParam("objects") String objects) {
    Map<String, String> votes;

    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {
        setup(context);
        DawidSkene ds = dscache.getDawidSkene(id);
        if (null == objects)
            votes = ds.getMajorityVote();
        else {
            Collection<String> objectNames = JSONUtils.gson.fromJson(objects, JSONUtils.stringSetType);
            votes = ds.getMajorityVote(objectNames);
        }
        String message = "computing majority votes for " + (null == votes ? 0 : votes.size()) + " objects ";
        logger.info(message);
        return Response.ok(JSONUtils.gson.toJson(votes)).build();

    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {

        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();
}

From source file:com.datascience.gal.service.Service.java

/**
 * computes class probs objects/*from  w  w w .j av a2 s  .co m*/
 * 
 * @return map of majority votes
 */
@POST
@Path("objectProbs")
@Produces(MediaType.APPLICATION_JSON)
public Response objectProbs(@FormParam("id") String idstr, @FormParam("objects") String objects) {
    Map<String, Map<String, Double>> votes;

    String id = "" + 0;
    if (null == idstr) {
        logger.info("no id input, using id 0");
    } else {
        id = idstr;
    }

    try {
        setup(context);
        DawidSkene ds = dscache.getDawidSkene(id);
        if (null == objects)
            votes = ds.getObjectProbs();
        else {
            Collection<String> objectNames = JSONUtils.gson.fromJson(objects, JSONUtils.stringSetType);
            votes = ds.getObjectProbs(objectNames);
        }
        String message = "computing object probs for " + (null == votes ? 0 : votes.size()) + " objects ";
        logger.info(message);
        return Response.ok(JSONUtils.gson.toJson(votes)).build();

    } catch (IOException e) {
        logger.error("ioexception: " + e.getLocalizedMessage());
    } catch (ClassNotFoundException e) {
        logger.error("class not found exception: " + e.getLocalizedMessage());
    } catch (SQLException e) {
        logger.error("sql exception: " + e.getLocalizedMessage());
    } catch (Exception e) {

        logger.error(e.getLocalizedMessage());
    }
    return Response.status(500).build();
}