Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang Exception getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.kylinolap.job.hadoop.cube.RangeKeyDistributionJob.java

@Override
public int run(String[] args) throws Exception {
    Options options = new Options();

    try {/*  ww w. j a  v  a 2  s .  co  m*/
        options.addOption(OPTION_INPUT_PATH);
        options.addOption(OPTION_OUTPUT_PATH);
        options.addOption(OPTION_JOB_NAME);
        options.addOption(OPTION_CUBE_NAME);

        parseOptions(options, args);

        // start job
        String jobName = getOptionValue(OPTION_JOB_NAME);
        job = Job.getInstance(getConf(), jobName);

        File JarFile = new File(KylinConfig.getInstanceFromEnv().getKylinJobJarPath());
        if (JarFile.exists()) {
            job.setJar(KylinConfig.getInstanceFromEnv().getKylinJobJarPath());
        } else {
            job.setJarByClass(this.getClass());
        }

        addInputDirs(getOptionValue(OPTION_INPUT_PATH), job);

        Path output = new Path(getOptionValue(OPTION_OUTPUT_PATH));
        FileOutputFormat.setOutputPath(job, output);
        // job.getConfiguration().set("dfs.block.size", "67108864");

        // Mapper
        job.setInputFormatClass(SequenceFileInputFormat.class);
        job.setMapperClass(RangeKeyDistributionMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        // Reducer - only one
        job.setReducerClass(RangeKeyDistributionReducer.class);
        job.setOutputFormatClass(SequenceFileOutputFormat.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);
        job.setNumReduceTasks(1);

        this.deletePath(job.getConfiguration(), output);

        String cubeName = getOptionValue(OPTION_CUBE_NAME).toUpperCase();
        CubeManager cubeMgr = CubeManager.getInstance(KylinConfig.getInstanceFromEnv());
        CubeInstance cube = cubeMgr.getCube(cubeName);
        CubeCapacity cubeCapacity = cube.getDescriptor().getCapacity();
        job.getConfiguration().set(BatchConstants.CUBE_CAPACITY, cubeCapacity.toString());

        return waitForCompletion(job);
    } catch (Exception e) {
        printUsage(options);
        log.error(e.getLocalizedMessage(), e);
        return 2;
    }
}

From source file:com.kylinolap.job.hadoop.hbase.BulkLoadJob.java

@Override
public int run(String[] args) throws Exception {
    Options options = new Options();

    try {/*from www.j a  va 2s  . c  o  m*/
        options.addOption(OPTION_INPUT_PATH);
        options.addOption(OPTION_HTABLE_NAME);
        options.addOption(OPTION_CUBE_NAME);
        parseOptions(options, args);

        String tableName = getOptionValue(OPTION_HTABLE_NAME).toUpperCase();
        // e.g
        // /tmp/kylin-3f150b00-3332-41ca-9d3d-652f67f044d7/test_kylin_cube_with_slr_ready_2_segments/hfile/
        // end with "/"
        String input = getOptionValue(OPTION_INPUT_PATH);

        Configuration conf = HBaseConfiguration.create(getConf());
        FileSystem fs = FileSystem.get(conf);

        String cubeName = getOptionValue(OPTION_CUBE_NAME).toUpperCase();
        KylinConfig config = KylinConfig.getInstanceFromEnv();
        CubeManager cubeMgr = CubeManager.getInstance(config);
        CubeInstance cube = cubeMgr.getCube(cubeName);
        CubeDesc cubeDesc = cube.getDescriptor();
        FsPermission permission = new FsPermission((short) 0777);
        for (HBaseColumnFamilyDesc cf : cubeDesc.getHBaseMapping().getColumnFamily()) {
            String cfName = cf.getName();
            fs.setPermission(new Path(input + cfName), permission);
        }

        String[] newArgs = new String[2];
        newArgs[0] = input;
        newArgs[1] = tableName;
        int ret = ToolRunner.run(new LoadIncrementalHFiles(conf), newArgs);
        return ret;
    } catch (Exception e) {
        printUsage(options);
        e.printStackTrace(System.err);
        log.error(e.getLocalizedMessage(), e);
        return 2;
    }
}

From source file:org.openvoters.android.tasks.RemoteAPIVoteTask.java

@Override
protected Boolean doInBackground(Object... params) {
    callback = (RemoteAPIVoteCallback) params[0];
    Item party = (Item) params[1];//ww  w  .ja va2  s .co  m
    uniqueVoterID = (String) params[2];

    try {
        String remoteAPIURL = String.format("%s/%s", RemoteAPI.getBaseURL(), "vote");
        makeRequest(remoteAPIURL, party, uniqueVoterID);
        return Boolean.TRUE;

    } catch (Exception e) {
        Log.e("Remote API", String.format("Errore (%s): %s", e, e.getLocalizedMessage()));

        e.printStackTrace();
        exc = e;
        return Boolean.FALSE;
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.TestCredentials.java

@Override
protected UserInfo doInBackground(Void... params) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("tmp_username", null);
    String password = credentials.getString("tmp_password", null);
    String url = credentials.getString("tmp_url", null) + Values.SERVICE_USER + "login";

    setState(RUNNING, R.string.working_ws_credentials);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    try {/*from  w  ww .ja v a  2  s .co m*/
        // Make the network request
        Log.d(TAG, url);
        ResponseEntity<UserInfo> userInfo = restTemplate.exchange(url, HttpMethod.GET, entity, UserInfo.class);
        return (Values.user = userInfo.getBody());
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
        return null;
    } finally {
        setState(DONE);
    }
}

From source file:org.opencron.server.websocket.TerminalHandler.java

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    super.afterConnectionEstablished(session);
    String sshSessionId = OpencronTools.getSshSessionId();
    if (sshSessionId != null) {
        final Terminal terminal = TerminalContext.remove(sshSessionId);
        if (terminal != null) {
            try {
                session.sendMessage(new TextMessage("Welcome to Opencron Terminal! Connect Starting."));
                getClient(session, terminal);
                int cols = Integer.parseInt(session.getAttributes().get("cols").toString());
                int rows = Integer.parseInt(session.getAttributes().get("rows").toString());
                int width = Integer.parseInt(session.getAttributes().get("width").toString());
                int height = Integer.parseInt(session.getAttributes().get("height").toString());
                terminalClient.openTerminal(cols, rows, width, height);
                terminalService.login(terminal);
            } catch (Exception e) {
                if (e.getLocalizedMessage().replaceAll("\\s+", "").contentEquals("Operationtimedout")) {
                    session.sendMessage(new TextMessage("Sorry! Connect timed out, please try again. "));
                } else {
                    session.sendMessage(new TextMessage("Sorry! Operation error, please try again. "));
                }//  w  ww. j av  a 2 s . c o  m
                terminalClient.disconnect();
                session.close();
            }
        } else {
            this.terminalClient.disconnect();
            session.sendMessage(new TextMessage("Sorry! Connect failed, please try again. "));
            session.close();
        }
    }
}

From source file:com.kylinolap.job.hadoop.invertedindex.RandomKeyDistributionJob.java

@Override
public int run(String[] args) throws Exception {
    Options options = new Options();

    try {/*from  ww  w.j  a va2s. co m*/
        options.addOption(OPTION_INPUT_PATH);
        options.addOption(OPTION_OUTPUT_PATH);
        options.addOption(OPTION_JOB_NAME);
        options.addOption(OPTION_KEY_CLASS);
        options.addOption(OPTION_REGION_MB);

        parseOptions(options, args);

        // start job
        String jobName = getOptionValue(OPTION_JOB_NAME);
        job = Job.getInstance(getConf(), jobName);

        job.setJarByClass(this.getClass());
        addInputDirs(getOptionValue(OPTION_INPUT_PATH), job);

        Path output = new Path(getOptionValue(OPTION_OUTPUT_PATH));
        FileOutputFormat.setOutputPath(job, output);

        String keyClass = getOptionValue(OPTION_KEY_CLASS);
        Class<?> keyClz = Class.forName(keyClass);

        int regionMB = Integer.parseInt(getOptionValue(OPTION_REGION_MB));

        // Mapper
        job.setInputFormatClass(SequenceFileInputFormat.class);
        job.setMapperClass(RandomKeyDistributionMapper.class);
        job.setMapOutputKeyClass(keyClz);
        job.setMapOutputValueClass(NullWritable.class);

        // Reducer - only one
        job.setReducerClass(RandomKeyDistributionReducer.class);
        job.setOutputFormatClass(SequenceFileOutputFormat.class);
        job.setOutputKeyClass(keyClz);
        job.setOutputValueClass(NullWritable.class);
        job.setNumReduceTasks(1);

        this.deletePath(job.getConfiguration(), output);

        // total map input MB
        double totalMapInputMB = this.getTotalMapInputMB();
        int regionCount = Math.max(1, (int) (totalMapInputMB / regionMB));
        int mapSampleNumber = 1000;
        System.out.println("Total Map Input MB: " + totalMapInputMB);
        System.out.println("Region Count: " + regionCount);

        // set job configuration
        job.getConfiguration().set(BatchConstants.MAPPER_SAMPLE_NUMBER, String.valueOf(mapSampleNumber));
        job.getConfiguration().set(BatchConstants.REGION_NUMBER, String.valueOf(regionCount));

        return waitForCompletion(job);
    } catch (Exception e) {
        printUsage(options);
        log.error(e.getLocalizedMessage(), e);
        return 2;
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateArtifact.java

/**
 * Method, where artifact information is pushed to server in order to create user.
 * All heavy lifting is made here.//w ww . ja  va2s. c o m
 *
 * @param artifacts only one Artifact object is accepted
 * @return information about created artifact
 */
@Override
protected Artifact doInBackground(Artifact... artifacts) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_ARTIFACTS;

    setState(RUNNING, R.string.working_ws_create_artifact);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    Artifact artifact = artifacts[0];

    try {
        Log.d(TAG, url);

        HttpEntity<Artifact> entity = new HttpEntity<Artifact>(artifact, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, Artifact.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateDigitization.java

/**
 * Method, where digitization information is pushed to server in order to create user.
 * All heavy lifting is made here./*from  w  w w  . jav a2  s.  c o m*/
 *
 * @param digitizations only one Digitization object is accepted
 * @return information about created digitization
 */
@Override
protected Digitization doInBackground(Digitization... digitizations) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_DIGITIZATIONS;

    setState(RUNNING, R.string.working_ws_create_digitization);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    Digitization digitization = digitizations[0];

    try {
        Log.d(TAG, url);

        HttpEntity<Digitization> entity = new HttpEntity<Digitization>(digitization, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, Digitization.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateDisease.java

/**
 * Method, where Disease information is pushed to server in order to create user.
 * All heavy lifting is made here.//from w w  w .  j  a  va  2  s . c  o  m
 *
 * @param diseases only one Disease object is accepted
 * @return information about created disease
 */
@Override
protected Disease doInBackground(Disease... diseases) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_DISEASES;

    setState(RUNNING, R.string.working_ws_create_disease);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    Disease disease = diseases[0];

    try {
        Log.d(TAG, url);

        HttpEntity<Disease> entity = new HttpEntity<Disease>(disease, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, Disease.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateElectrodeFix.java

/**
 * Method, where electrode fix information is pushed to server in order to create user.
 * All heavy lifting is made here.//from  w ww .  j a  v a 2 s  . c o  m
 *
 * @param electrodeFixes only one ElectrodeFix object is accepted
 * @return information about created electrode fix
 */
@Override
protected ElectrodeFix doInBackground(ElectrodeFix... electrodeFixes) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_FIXLIST;

    setState(RUNNING, R.string.working_ws_create_electrode_fix);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    ElectrodeFix fix = electrodeFixes[0];

    try {
        Log.d(TAG, url);

        HttpEntity<ElectrodeFix> entity = new HttpEntity<ElectrodeFix>(fix, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, ElectrodeFix.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}