Example usage for org.apache.commons.lang ArrayUtils addAll

List of usage examples for org.apache.commons.lang ArrayUtils addAll

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils addAll.

Prototype

public static double[] addAll(double[] array1, double[] array2) 

Source Link

Document

Adds all the elements of the given arrays into a new array.

Usage

From source file:com.oneops.inductor.WorkOrderExecutor.java

/**
 * Calls local or remote chef to do recipe [ciClassname::wo.getRfcCi().rfcAction]
 *
 * @param wo CmsWorkOrderSimple/*w w w .j a v a 2s .  c om*/
 */
private void runWorkOrder(CmsWorkOrderSimple wo) {

    // check to see if should be remote by looking at proxy
    Boolean isRemote = isRemoteChefCall(wo);

    // file-based request keyed by deployment record id - remotely by
    // class.ciName for ease of debug
    String remoteFileName = getRemoteFileName(wo);
    String fileName = config.getDataDir() + "/" + wo.getDpmtRecordId() + ".json";
    logger.info("writing config to: " + fileName + " remote: " + remoteFileName);
    // assume failed; gets set to COMPLETE at the end
    wo.setDpmtRecordState(FAILED);
    String appName = normalizeClassName(wo);
    String logKey = getLogKey(wo);
    logger.info(logKey + " Inductor: " + config.getIpAddr());
    wo.putSearchTag("inductor", config.getIpAddr());

    writeChefRequest(wo, fileName);

    String cookbookPath = getCookbookPath(wo.getRfcCi().getCiClassName());
    logger.info("cookbookPath: " + cookbookPath);

    Set<String> serviceCookbookPaths = null;

    // sync cookbook and chef json request to remote site
    String host = null;
    String user = "oneops";

    String keyFile = null;
    String port = "22";

    if (isRemote) {

        host = getWorkOrderHost(wo, logKey);

        try {
            keyFile = writePrivateKey(wo);
        } catch (KeyNotFoundException e) {
            logger.error(e.getMessage());
            return;
        }
        if (host.contains(":")) {
            String[] parts = host.split(":");
            host = parts[0];
            port = parts[1];
            logger.info("using port from " + config.getIpAttribute());
        }

        long rsyncStartTime = System.currentTimeMillis();
        String[] rsyncCmdLineWithKey = rsyncCmdLine.clone();
        rsyncCmdLineWithKey[4] += "-p " + port + " -qi " + keyFile;

        // return with failure if empty
        if (host == null || host.isEmpty()) {
            wo.setComments("failed : missing host/ip cannot connect");
            removeFile(wo, keyFile);
            return;
        }

        String rfcAction = wo.getRfcCi().getRfcAction();

        logger.info("rfc: " + wo.getRfcCi().getRfcId() + ", appName: " + appName + ", rfcAction: " + rfcAction);

        // v2 install base done via compute cookbook
        // compute::remote logic can be removed once v1 packs are decommed
        //skip base install for propagation updates
        if (appName.equalsIgnoreCase(COMPUTE) && rfcAction.equalsIgnoreCase(REMOTE)
                && !isPropagationUpdate(wo)) {

            logger.info(logKey + " ### BASE INSTALL");
            wo.setComments("");
            runBaseInstall(processRunner, wo, host, port, logKey, keyFile);
            if (!wo.getComments().isEmpty()) {
                logger.info(logKey + " failed base install.");
                return;
            }
        }
        String baseDir = config.getCircuitDir().replace("packer", cookbookPath);
        String components = baseDir + "/components";
        String destination = "/home/" + user + "/" + cookbookPath;

        // always sync base cookbooks/modules
        String[] cmdLine = (String[]) ArrayUtils.addAll(rsyncCmdLineWithKey,
                new String[] { components, user + "@" + host + ":" + destination });
        logger.info(logKey + " ### SYNC BASE: " + components);

        if (!host.equals(TEST_HOST)) {
            ProcessResult result = processRunner
                    .executeProcessRetry(new ExecutionContext(wo, cmdLine, logKey, retryCount));
            if (result.getResultCode() > 0) {
                if (DELETE.equals(wo.getRfcCi().getRfcAction())) {
                    List<CmsRfcCISimple> managedViaRfcs = wo.getPayLoad().get(MANAGED_VIA);
                    if (managedViaRfcs != null && managedViaRfcs.size() > 0
                            && DELETE.equals(managedViaRfcs.get(0).getRfcAction())) {
                        if (failOnDeleteFailure(wo)) {
                            logger.info(logKey
                                    + "wo failed due to unreachable compute, this component is set to fail on delete failures");
                        } else {
                            logger.warn(logKey
                                    + "wo failed due to unreachable compute, but marking ok due to ManagedVia rfcAction==delete");
                            wo.setDpmtRecordState(COMPLETE);
                        }
                    } else {
                        wo.setComments("FATAL: "
                                + generateRsyncErrorMessage(result.getResultCode(), host + ":" + port));
                    }
                } else {
                    wo.setComments(
                            "FATAL: " + generateRsyncErrorMessage(result.getResultCode(), host + ":" + port));
                }

                handleRsyncFailure(wo, keyFile);
                return;
            }
        }

        // rsync exec-order shared
        String sharedComponents = config.getCircuitDir().replace("packer", "shared/");
        destination = "/home/" + user + "/shared/";
        cmdLine = (String[]) ArrayUtils.addAll(rsyncCmdLineWithKey,
                new String[] { sharedComponents, user + "@" + host + ":" + destination });
        logger.info(logKey + " ### SYNC SHARED: " + sharedComponents);

        if (!host.equals(TEST_HOST)) {
            ProcessResult result = processRunner
                    .executeProcessRetry(new ExecutionContext(wo, cmdLine, logKey, retryCount));
            if (result.getResultCode() > 0) {
                inductorStat.addRsyncFailed();
                wo.setComments(
                        "FATAL: " + generateRsyncErrorMessage(result.getResultCode(), host + ":" + port));
                handleRsyncFailure(wo, keyFile);
                return;
            }
        }

        serviceCookbookPaths = syncServiceCookbooks(wo, cookbookPath, user, rsyncCmdLineWithKey, host, port,
                logKey, keyFile);

        // put workorder
        cmdLine = (String[]) ArrayUtils.addAll(rsyncCmdLineWithKey,
                new String[] { fileName, user + "@" + host + ":" + remoteFileName });
        logger.info(logKey + " ### SYNC: " + remoteFileName);
        if (!host.equals(TEST_HOST)) {
            ProcessResult result = processRunner
                    .executeProcessRetry(new ExecutionContext(wo, cmdLine, logKey, retryCount));
            if (result.getResultCode() > 0) {
                wo.setComments(
                        "FATAL: " + generateRsyncErrorMessage(result.getResultCode(), host + ":" + port));
                handleRsyncFailure(wo, keyFile);
                return;
            }
        }
        wo.putSearchTag(CmsConstants.INDUCTOR_RSYNC_TIME,
                Long.toString(System.currentTimeMillis() - rsyncStartTime));
    }

    // run the chef command
    String[] cmd = null;
    if (isRemote) {
        String vars = getProxyEnvVars(wo);
        // exec-order.rb takes -d switch and 3 args: impl, json node
        // structure w/ work/actionorder, and cookbook path
        String debugFlag = "";
        if (isDebugEnabled(wo)) {
            debugFlag = "-d";
        }

        String additionalCookbookPaths = "";
        if (serviceCookbookPaths != null && serviceCookbookPaths.size() > 0) {
            additionalCookbookPaths = String.join(",", serviceCookbookPaths);
        }

        String remoteCmd = "sudo " + vars + " shared/exec-order.rb " + wo.getRfcCi().getImpl() + " "
                + remoteFileName + " " + cookbookPath + " " + additionalCookbookPaths + " " + debugFlag;

        cmd = (String[]) ArrayUtils.addAll(sshCmdLine,
                new String[] { keyFile, "-p " + port, user + "@" + host, remoteCmd });
        logger.info(logKey + " ### EXEC: " + user + "@" + host + " " + remoteCmd);
        int woRetryCount = getRetryCountForWorkOrder(wo);
        if (!host.equals(TEST_HOST)) {
            ProcessResult result = processRunner
                    .executeProcessRetry(new ExecutionContext(wo, cmd, logKey, woRetryCount));

            // set the result status
            if (result.getResultCode() != 0) {
                inductorStat.addWoFailed();
                // mark as complete when rfc and managed_via is DELETE
                if (DELETE.equals(wo.getRfcCi().getRfcAction())) {
                    List<CmsRfcCISimple> managedViaRfcs = wo.getPayLoad().get(MANAGED_VIA);
                    if (managedViaRfcs != null && managedViaRfcs.size() > 0
                            && DELETE.equals(managedViaRfcs.get(0).getRfcAction())) {
                        if (failOnDeleteFailure(wo)) {
                            logger.info(logKey + "wo failed, this component is set to fail on delete failures");
                        } else {
                            logger.warn(
                                    logKey + "wo failed, but marking ok due to ManagedVia rfcAction==delete");
                            wo.setDpmtRecordState(COMPLETE);
                        }
                    }
                } else {
                    String comments = getCommentsFromResult(result);
                    logger.error(logKey + comments);
                    wo.setComments(comments);
                }

                removeRemoteWorkOrder(wo, keyFile, processRunner);
                removeFile(wo, keyFile);
                copySearchTagsFromResult(wo, result);
                return;
            }
            // remove remote workorder for success and failure.
            removeRemoteWorkOrder(wo, keyFile, processRunner);
            setResultCi(result, wo);
        }

        wo.setDpmtRecordState(COMPLETE);
        removeFile(wo, keyFile);

    } else {
        runLocalWorkOrder(processRunner, wo, appName, logKey, fileName, cookbookPath);
    }
    if (!isDebugEnabled(wo))
        removeFile(fileName);
}

From source file:marytts.unitselection.analysis.Phone.java

/**
 * Get the F0 factor for each Datagram in this phone's left and right units
 * //from  w w  w.ja v  a  2 s.com
 * @return the F0 factors, in an array with one value per Datagram
 */
public double[] getF0Factors() {
    return ArrayUtils.addAll(getLeftF0Factors(), getRightF0Factors());
}

From source file:canreg.client.gui.components.FastFilterInternalFrame.java

private void refreshVariableList() {
    if (tableName.equalsIgnoreCase(Globals.TUMOUR_AND_PATIENT_JOIN_TABLE_NAME)) {
        variablesInTable = (DatabaseVariablesListElement[]) ArrayUtils.addAll(patientVariablesInDB,
                tumourVariablesInDB);//w ww  .  ja va  2  s  . c  om
    } else if (tableName.equalsIgnoreCase(Globals.SOURCE_AND_TUMOUR_JOIN_TABLE_NAME)) {
        variablesInTable = (DatabaseVariablesListElement[]) ArrayUtils.addAll(sourceVariablesInDB,
                tumourVariablesInDB);
    } else if (tableName.equalsIgnoreCase(Globals.SOURCE_AND_TUMOUR_AND_PATIENT_JOIN_TABLE_NAME)) {
        variablesInTable = (DatabaseVariablesListElement[]) ArrayUtils.addAll(sourceVariablesInDB,
                tumourVariablesInDB);
        variablesInTable = (DatabaseVariablesListElement[]) ArrayUtils.addAll(variablesInTable,
                patientVariablesInDB);
    } else if (tableName.equalsIgnoreCase(Globals.PATIENT_TABLE_NAME)) {
        variablesInTable = patientVariablesInDB;
    } else if (tableName.equalsIgnoreCase(Globals.TUMOUR_TABLE_NAME)) {
        variablesInTable = tumourVariablesInDB;
    } else if (tableName.equalsIgnoreCase(Globals.SOURCE_TABLE_NAME)) {
        variablesInTable = sourceVariablesInDB;
    }
    Arrays.sort(variablesInTable, comparator);
    variableComboBox.setModel(new DefaultComboBoxModel(variablesInTable));
    variableComboBox.setSelectedItem(0);
    updatePossibleValues();
}

From source file:de.tudarmstadt.ukp.dkpro.core.berkeleyparser.BerkeleyParserTest.java

private JCas runTest(String aLanguage, String aVariant, String aText, boolean aGoldPos, Object... aExtraParams)
        throws Exception {
    AggregateBuilder aggregate = new AggregateBuilder();

    if (aGoldPos) {
        aggregate.add(createEngineDescription(OpenNlpPosTagger.class));
    }//from  w w  w.j a v a  2 s.c o m

    Object[] params = new Object[] { BerkeleyParser.PARAM_VARIANT, aVariant, BerkeleyParser.PARAM_PRINT_TAGSET,
            true, BerkeleyParser.PARAM_WRITE_PENN_TREE, true, BerkeleyParser.PARAM_WRITE_POS, !aGoldPos,
            BerkeleyParser.PARAM_READ_POS, aGoldPos };
    params = ArrayUtils.addAll(params, aExtraParams);
    aggregate.add(createEngineDescription(BerkeleyParser.class, params));

    return TestRunner.runTest(aggregate.createAggregateDescription(), aLanguage, aText);
}

From source file:gda.scan.ScanDataPoint.java

/**
 * @return all Scannable positions as strings using the given format
 *//*from w w  w.  j a v a  2s.  c o  m*/
@Override
public String[] getPositionsAsFormattedStrings() {

    String[] strings = new String[0];
    if (getPositions() != null) {
        int index = 0;
        for (Object data : getPositions()) {
            PlottableDetectorData wrapper = new DetectorDataWrapper(data);
            Double[] dvals = wrapper.getDoubleVals();
            String[] formattedVals = new String[dvals.length];
            String[] formats = this.scannableFormats[index];
            for (int j = 0; j < dvals.length; j++) {
                formattedVals[j] = String.format(formats[j], dvals[j]);
            }
            strings = (String[]) ArrayUtils.addAll(strings, formattedVals);
            index++;
        }
    }
    if (strings.length != getPositionHeader().size()) {
        throw new IllegalArgumentException("Position data does not hold the expected number of fields");
    }
    return strings;
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRJobRequest.java

public String[] getUpdatedVariableNames() {
    List<String> tmp = new ArrayList<String>();
    if ((!hasUnsafedVariableNames) && (!hasRecodedVariables())) {
        // neither renemaed nor recoded vars
        return getVariableNames();
    } else if (hasUnsafedVariableNames && !hasRecodedVariables()) {
        // renamed vars only
        return safeVarNames;
    } else if (!hasUnsafedVariableNames && hasRecodedVariables()) {
        // recoded vars only
        return (String[]) ArrayUtils.addAll(getVariableNames(), getRecodedVarNameSet());
    } else {//from w w w .  j a v a  2  s  . c  om
        // both renamed and rcoded vars
        return (String[]) ArrayUtils.addAll(safeVarNames, getRecodedVarNameSet());
    }

}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRJobRequest.java

public String[] getUpdatedVariableLabels() {
    if (hasRecodedVariables()) {
        return (String[]) ArrayUtils.addAll(getVariableLabels(), getRecodedVarLabelSet());
    } else {//  www  . j a v a2 s. co m
        return getVariableLabels();
    }
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRJobRequest.java

public String[] getUpdatedVariableIds() {
    if (hasRecodedVariables()) {
        return (String[]) ArrayUtils.addAll(getVariableIds(), getRecodedVarIdSet());
    } else {/*from  w  ww .  j a va2 s. co  m*/
        return getVariableIds();
    }
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRJobRequest.java

public int[] getUpdatedVariableTypes() {
    if (hasRecodedVariables()) {
        return ArrayUtils.addAll(getVariableTypes(), getRecodedVarTypeSet());
    } else {//from  w ww.jav  a  2s  .co  m
        return getVariableTypes();
    }
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRJobRequest.java

public int[] getUpdatedVariableTypesWithBoolean() {
    if (hasRecodedVariables()) {
        return ArrayUtils.addAll(getVariableTypesWithBoolean(), getRecodedVarTypeSet());
    } else {// w  w  w . j a va 2s .  c  o  m
        return getVariableTypes();
    }
}