Search in sources :

Example 21 with DeploymentType

use of org.voltdb.compiler.deploymentfile.DeploymentType in project voltdb by VoltDB.

the class RealVoltDB method outputDeployment.

private int outputDeployment(Configuration config) {
    try {
        File configInfoDir = new VoltFile(config.m_voltdbRoot, Constants.CONFIG_DIR);
        File depFH = new VoltFile(configInfoDir, "deployment.xml");
        if (!depFH.isFile() || !depFH.canRead()) {
            consoleLog.fatal("Failed to get configuration or deployment configuration is invalid. " + depFH.getAbsolutePath());
            return -1;
        }
        config.m_pathToDeployment = depFH.getCanonicalPath();
    } catch (IOException e) {
        consoleLog.fatal("Failed to read deployment: " + e.getMessage());
        return -1;
    }
    ReadDeploymentResults readDepl = readPrimedDeployment(config);
    try {
        DeploymentType dt = CatalogUtil.updateRuntimeDeploymentPaths(readDepl.deployment);
        // We don't have catalog context so host count is not there.
        String out;
        if ((out = CatalogUtil.getDeployment(dt, true)) != null) {
            if ((new File(config.m_getOutput)).exists() && !config.m_forceGetCreate) {
                consoleLog.fatal("Failed to save deployment, file already exists: " + config.m_getOutput);
                return -1;
            }
            try (FileOutputStream fos = new FileOutputStream(config.m_getOutput.trim())) {
                fos.write(out.getBytes());
            } catch (IOException e) {
                consoleLog.fatal("Failed to write deployment to " + config.m_getOutput + " : " + e.getMessage());
                return -1;
            }
            consoleLog.info("Deployment configuration saved in " + config.m_getOutput.trim());
        } else {
            consoleLog.fatal("Failed to get configuration or deployment configuration is invalid.");
            return -1;
        }
    } catch (Exception e) {
        consoleLog.fatal("Failed to get configuration or deployment configuration is invalid. " + "Please make sure voltdbroot is a valid directory. " + e.getMessage());
        return -1;
    }
    return 0;
}
Also used : VoltFile(org.voltdb.utils.VoltFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException)

Example 22 with DeploymentType

use of org.voltdb.compiler.deploymentfile.DeploymentType in project voltdb by VoltDB.

the class RealVoltDB method readPrimedDeployment.

ReadDeploymentResults readPrimedDeployment(Configuration config) {
    /*
         * Debate with the cluster what the deployment file should be
         */
    try {
        byte[] deploymentBytes = null;
        try {
            deploymentBytes = org.voltcore.utils.CoreUtils.urlToBytes(config.m_pathToDeployment);
        } catch (Exception ex) {
        //Let us get bytes from ZK
        }
        if (deploymentBytes == null) {
            hostLog.error("Deployment information could not be obtained from cluster node or locally");
            VoltDB.crashLocalVoltDB("No such deployment file: " + config.m_pathToDeployment, false, null);
        }
        DeploymentType deployment = CatalogUtil.getDeployment(new ByteArrayInputStream(deploymentBytes));
        // wasn't a valid xml deployment file
        if (deployment == null) {
            hostLog.error("Not a valid XML deployment file at URL: " + config.m_pathToDeployment);
            VoltDB.crashLocalVoltDB("Not a valid XML deployment file at URL: " + config.m_pathToDeployment, false, null);
            return new ReadDeploymentResults(deploymentBytes, deployment);
        }
        // Override local sites count if possible
        if (config.m_sitesperhost == VoltDB.UNDEFINED) {
            config.m_sitesperhost = deployment.getCluster().getSitesperhost();
        } else {
            hostLog.info("Set the local sites count to " + config.m_sitesperhost);
            consoleLog.info("CLI overrides the local sites count to " + config.m_sitesperhost);
        }
        NodeSettings nodeSettings = null;
        // providers
        switch(config.m_startAction) {
            case GET:
                // once a voltdbroot is inited, the path properties contain the true path values
                Settings.initialize(config.m_voltdbRoot);
                // only override the local sites count
                nodeSettings = NodeSettings.create(config.asNodeSettingsMap());
                break;
            case PROBE:
                // once a voltdbroot is inited, the path properties contain the true path values
                Settings.initialize(config.m_voltdbRoot);
                // only override the local sites count
                nodeSettings = NodeSettings.create(config.asNodeSettingsMap());
                File nodeSettingsFH = new File(getConfigDirectory(config), "path.properties");
                consoleLog.info("Loaded node-specific settings from " + nodeSettingsFH.getPath());
                hostLog.info("Loaded node-specific settings from " + nodeSettingsFH.getPath());
                break;
            case INITIALIZE:
                Settings.initialize(config.m_voltdbRoot);
                // voltdbroot value from config overrides voltdbroot value in the deployment
                // file
                nodeSettings = NodeSettings.create(config.asNodeSettingsMap(), config.asPathSettingsMap(), CatalogUtil.asNodeSettingsMap(deployment));
                break;
            default:
                nodeSettings = NodeSettings.create(config.asNodeSettingsMap(), CatalogUtil.asNodeSettingsMap(deployment));
                Settings.initialize(nodeSettings.getVoltDBRoot());
                config.m_voltdbRoot = nodeSettings.getVoltDBRoot();
                break;
        }
        m_nodeSettings = nodeSettings;
        //Now its safe to save node settings
        if (config.m_startAction != StartAction.GET) {
            m_nodeSettings.store();
        }
        if (config.m_startAction == StartAction.PROBE) {
            // once initialized the path properties contain the true path values
            if (config.m_hostCount == VoltDB.UNDEFINED) {
                config.m_hostCount = 1;
            }
        } else {
            config.m_hostCount = deployment.getCluster().getHostcount();
        }
        /*
             * Check for invalid deployment file settings (enterprise-only) in the community edition.
             * Trick here is to print out all applicable problems and then stop, rather than stopping
             * after the first one is found.
             */
        if (!config.m_isEnterprise) {
            boolean shutdownDeployment = false;
            boolean shutdownAction = false;
            // check license features for community version
            if ((deployment.getCluster() != null) && (deployment.getCluster().getKfactor() > 0)) {
                consoleLog.error("K-Safety is not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            if ((deployment.getSnapshot() != null) && (deployment.getSnapshot().isEnabled())) {
                consoleLog.error("Snapshots are not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            if ((deployment.getCommandlog() != null) && (deployment.getCommandlog().isEnabled())) {
                consoleLog.error("Command logging is not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            if ((deployment.getExport() != null) && deployment.getExport().getConfiguration() != null && !deployment.getExport().getConfiguration().isEmpty()) {
                consoleLog.error("Export is not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            // check the start action for the community edition
            if (m_config.m_startAction != StartAction.CREATE) {
                consoleLog.error("Start action \"" + m_config.m_startAction.getClass().getSimpleName() + "\" is not supported in the community edition of VoltDB.");
                shutdownAction = true;
            }
            // if the process needs to stop, try to be helpful
            if (shutdownAction || shutdownDeployment) {
                String msg = "This process will exit. Please run VoltDB with ";
                if (shutdownDeployment) {
                    msg += "a deployment file compatible with the community edition";
                }
                if (shutdownDeployment && shutdownAction) {
                    msg += " and ";
                }
                if (shutdownAction && !shutdownDeployment) {
                    msg += "the CREATE start action";
                }
                msg += ".";
                VoltDB.crashLocalVoltDB(msg, false, null);
            }
        }
        return new ReadDeploymentResults(deploymentBytes, deployment);
    } catch (Exception e) {
        /*
             * When a settings exception is caught (e.g. reading a broken properties file),
             * we probably just want to crash the DB anyway
             */
        consoleLog.fatal(e.getMessage());
        VoltDB.crashLocalVoltDB(e.getMessage());
        return null;
    }
}
Also used : NodeSettings(org.voltdb.settings.NodeSettings) ByteArrayInputStream(java.io.ByteArrayInputStream) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException)

Example 23 with DeploymentType

use of org.voltdb.compiler.deploymentfile.DeploymentType in project voltdb by VoltDB.

the class CatalogUtil method getDeployment.

/**
     * Given the deployment object generate the XML
     *
     * @param deployment
     * @param indent
     * @return XML of deployment object.
     * @throws IOException
     */
public static String getDeployment(DeploymentType deployment, boolean indent) throws IOException {
    try {
        if (m_jc == null || m_schema == null) {
            throw new RuntimeException("Error schema validation.");
        }
        Marshaller marshaller = m_jc.createMarshaller();
        marshaller.setSchema(m_schema);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.valueOf(indent));
        StringWriter sw = new StringWriter();
        marshaller.marshal(new JAXBElement<>(new QName("", "deployment"), DeploymentType.class, deployment), sw);
        return sw.toString();
    } catch (JAXBException e) {
        // Convert some linked exceptions to more friendly errors.
        if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
            hostLog.error(e.getLinkedException().getMessage());
            return null;
        } else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
            hostLog.error("Error schema validating deployment.xml file. " + e.getLinkedException().getMessage());
            return null;
        } else {
            throw new RuntimeException(e);
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) FileNotFoundException(java.io.FileNotFoundException)

Example 24 with DeploymentType

use of org.voltdb.compiler.deploymentfile.DeploymentType in project voltdb by VoltDB.

the class CatalogUtil method getDeployment.

/**
     * Get a reference to the root <deployment> element from the deployment.xml file.
     * @param deployIS
     * @return Returns a reference to the root <deployment> element.
     */
@SuppressWarnings("unchecked")
public static DeploymentType getDeployment(InputStream deployIS) {
    try {
        if (m_jc == null || m_schema == null) {
            throw new RuntimeException("Error schema validation.");
        }
        Unmarshaller unmarshaller = m_jc.createUnmarshaller();
        unmarshaller.setSchema(m_schema);
        JAXBElement<DeploymentType> result = (JAXBElement<DeploymentType>) unmarshaller.unmarshal(deployIS);
        DeploymentType deployment = result.getValue();
        populateDefaultDeployment(deployment);
        return deployment;
    } catch (JAXBException e) {
        // Convert some linked exceptions to more friendly errors.
        if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
            hostLog.error(e.getLinkedException().getMessage());
            return null;
        } else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
            hostLog.error("Error schema validating deployment.xml file. " + e.getLinkedException().getMessage());
            return null;
        } else {
            throw new RuntimeException(e);
        }
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) Unmarshaller(javax.xml.bind.Unmarshaller) FileNotFoundException(java.io.FileNotFoundException)

Example 25 with DeploymentType

use of org.voltdb.compiler.deploymentfile.DeploymentType in project voltdb by VoltDB.

the class CatalogUtil method shallowClusterAndPathsClone.

/**
     * Creates a shallow clone of {@link DeploymentType} where all its
     * children references are copied except for {@link ClusterType}, and
     * {@link PathsType} which are newly instantiated
     * @param o
     * @return a shallow clone of {@link DeploymentType}
     */
public static DeploymentType shallowClusterAndPathsClone(DeploymentType o) {
    DeploymentType clone = new DeploymentType();
    clone.setPartitionDetection(o.getPartitionDetection());
    clone.setHeartbeat(o.getHeartbeat());
    clone.setHttpd(o.getHttpd());
    clone.setSnapshot(o.getSnapshot());
    clone.setExport(o.getExport());
    clone.setUsers(o.getUsers());
    clone.setCommandlog(o.getCommandlog());
    clone.setSystemsettings(o.getSystemsettings());
    clone.setSecurity(o.getSecurity());
    clone.setDr(o.getDr());
    clone.setImport(o.getImport());
    clone.setConsistency(o.getConsistency());
    ClusterType other = o.getCluster();
    ClusterType cluster = new ClusterType();
    cluster.setHostcount(other.getHostcount());
    cluster.setSitesperhost(other.getSitesperhost());
    cluster.setKfactor(other.getKfactor());
    cluster.setId(other.getId());
    cluster.setElastic(other.getElastic());
    cluster.setSchema(other.getSchema());
    clone.setCluster(cluster);
    PathsType prev = o.getPaths();
    PathsType paths = new PathsType();
    paths.setVoltdbroot(prev.getVoltdbroot());
    paths.setSnapshots(prev.getSnapshots());
    paths.setExportoverflow(prev.getExportoverflow());
    paths.setDroverflow(prev.getDroverflow());
    paths.setCommandlog(prev.getCommandlog());
    paths.setCommandlogsnapshot(prev.getCommandlogsnapshot());
    clone.setPaths(paths);
    clone.setSsl(o.getSsl());
    clone.setSnmp(o.getSnmp());
    return clone;
}
Also used : PathsType(org.voltdb.compiler.deploymentfile.PathsType) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) ClusterType(org.voltdb.compiler.deploymentfile.ClusterType)

Aggregations

DeploymentType (org.voltdb.compiler.deploymentfile.DeploymentType)27 File (java.io.File)20 FileInputStream (java.io.FileInputStream)9 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)7 IOException (java.io.IOException)6 VoltFile (org.voltdb.utils.VoltFile)6 JAXBException (javax.xml.bind.JAXBException)5 Configuration (org.voltdb.VoltDB.Configuration)5 Catalog (org.voltdb.catalog.Catalog)5 JAXBContext (javax.xml.bind.JAXBContext)4 Marshaller (javax.xml.bind.Marshaller)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SocketException (java.net.SocketException)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 JSONException (org.json_voltpatches.JSONException)3 VoltCompiler (org.voltdb.compiler.VoltCompiler)3 ClusterType (org.voltdb.compiler.deploymentfile.ClusterType)3