Search in sources :

Example 1 with HeartbeatType

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

the class RealVoltDB method readDeploymentAndCreateStarterCatalogContext.

boolean readDeploymentAndCreateStarterCatalogContext(VoltDB.Configuration config) {
    /*
         * Debate with the cluster what the deployment file should be
         */
    try {
        ZooKeeper zk = m_messenger.getZK();
        byte[] deploymentBytes = null;
        try {
            deploymentBytes = org.voltcore.utils.CoreUtils.urlToBytes(m_config.m_pathToDeployment);
        } catch (Exception ex) {
        //Let us get bytes from ZK
        }
        DeploymentType deployment = null;
        try {
            if (deploymentBytes != null) {
                CatalogUtil.writeCatalogToZK(zk, // Fill in innocuous values for non-deployment stuff
                0, 0L, 0L, // spin loop in Inits.LoadCatalog.run() needs
                new byte[] {}, // this to be of zero length until we have a real catalog.
                null, deploymentBytes);
                hostLog.info("URL of deployment: " + m_config.m_pathToDeployment);
            } else {
                CatalogAndIds catalogStuff = CatalogUtil.getCatalogFromZK(zk);
                deploymentBytes = catalogStuff.deploymentBytes;
            }
        } catch (KeeperException.NodeExistsException e) {
            CatalogAndIds catalogStuff = CatalogUtil.getCatalogFromZK(zk);
            byte[] deploymentBytesTemp = catalogStuff.deploymentBytes;
            if (deploymentBytesTemp != null) {
                //We will ignore the supplied or default deployment anyways.
                if (deploymentBytes != null && !m_config.m_deploymentDefault) {
                    byte[] deploymentHashHere = CatalogUtil.makeDeploymentHash(deploymentBytes);
                    if (!(Arrays.equals(deploymentHashHere, catalogStuff.getDeploymentHash()))) {
                        hostLog.warn("The locally provided deployment configuration did not " + " match the configuration information found in the cluster.");
                    } else {
                        hostLog.info("Deployment configuration pulled from other cluster node.");
                    }
                }
                //Use remote deployment obtained.
                deploymentBytes = deploymentBytesTemp;
            } else {
                hostLog.error("Deployment file could not be loaded locally or remotely, " + "local supplied path: " + m_config.m_pathToDeployment);
                deploymentBytes = null;
            }
        } catch (KeeperException.NoNodeException e) {
            // no deploymentBytes case is handled below. So just log this error.
            if (hostLog.isDebugEnabled()) {
                hostLog.debug("Error trying to get deployment bytes from cluster", e);
            }
        }
        if (deploymentBytes == null) {
            hostLog.error("Deployment information could not be obtained from cluster node or locally");
            VoltDB.crashLocalVoltDB("No such deployment file: " + m_config.m_pathToDeployment, false, null);
        }
        if (deployment == null) {
            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: " + m_config.m_pathToDeployment);
            VoltDB.crashLocalVoltDB("Not a valid XML deployment file at URL: " + m_config.m_pathToDeployment, false, null);
        }
        /*
             * 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 (!m_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);
            }
        }
        // note the heart beats are specified in seconds in xml, but ms internally
        HeartbeatType hbt = deployment.getHeartbeat();
        if (hbt != null) {
            m_config.m_deadHostTimeoutMS = hbt.getTimeout() * 1000;
            m_messenger.setDeadHostTimeout(m_config.m_deadHostTimeoutMS);
        } else {
            hostLog.info("Dead host timeout set to " + m_config.m_deadHostTimeoutMS + " milliseconds");
        }
        PartitionDetectionType pt = deployment.getPartitionDetection();
        if (pt != null) {
            m_config.m_partitionDetectionEnabled = pt.isEnabled();
            m_messenger.setPartitionDetectionEnabled(m_config.m_partitionDetectionEnabled);
        }
        // get any consistency settings into config
        ConsistencyType consistencyType = deployment.getConsistency();
        if (consistencyType != null) {
            m_config.m_consistencyReadLevel = Consistency.ReadLevel.fromReadLevelType(consistencyType.getReadlevel());
        }
        final String elasticSetting = deployment.getCluster().getElastic().trim().toUpperCase();
        if (elasticSetting.equals("ENABLED")) {
            TheHashinator.setConfiguredHashinatorType(HashinatorType.ELASTIC);
        } else if (!elasticSetting.equals("DISABLED")) {
            VoltDB.crashLocalVoltDB("Error in deployment file,  elastic attribute of " + "cluster element must be " + "'enabled' or 'disabled' but was '" + elasticSetting + "'", false, null);
        } else {
            TheHashinator.setConfiguredHashinatorType(HashinatorType.LEGACY);
        }
        // log system setting information
        SystemSettingsType sysType = deployment.getSystemsettings();
        if (sysType != null) {
            if (sysType.getElastic() != null) {
                hostLog.info("Elastic duration set to " + sysType.getElastic().getDuration() + " milliseconds");
                hostLog.info("Elastic throughput set to " + sysType.getElastic().getThroughput() + " mb/s");
            }
            if (sysType.getTemptables() != null) {
                hostLog.info("Max temptable size set to " + sysType.getTemptables().getMaxsize() + " mb");
            }
            if (sysType.getSnapshot() != null) {
                hostLog.info("Snapshot priority set to " + sysType.getSnapshot().getPriority() + " [0 - 10]");
            }
            if (sysType.getQuery() != null) {
                if (sysType.getQuery().getTimeout() > 0) {
                    hostLog.info("Query timeout set to " + sysType.getQuery().getTimeout() + " milliseconds");
                    m_config.m_queryTimeout = sysType.getQuery().getTimeout();
                } else if (sysType.getQuery().getTimeout() == 0) {
                    hostLog.info("Query timeout set to unlimited");
                    m_config.m_queryTimeout = 0;
                }
            }
        }
        // log a warning on console log if security setting is turned off, like durability warning.
        SecurityType securityType = deployment.getSecurity();
        if (securityType == null || !securityType.isEnabled()) {
            consoleLog.warn(SECURITY_OFF_WARNING);
        }
        // create a dummy catalog to load deployment info into
        Catalog catalog = new Catalog();
        // Need these in the dummy catalog
        Cluster cluster = catalog.getClusters().add("cluster");
        cluster.getDatabases().add("database");
        String result = CatalogUtil.compileDeployment(catalog, deployment, true);
        if (result != null) {
            // Any other non-enterprise deployment errors will be caught and handled here
            // (such as <= 0 host count)
            VoltDB.crashLocalVoltDB(result);
        }
        m_catalogContext = new CatalogContext(//txnid
        TxnEgo.makeZero(MpInitiator.MP_INIT_PID).getTxnId(), //timestamp
        0, catalog, new DbSettings(m_clusterSettings, m_nodeSettings), new byte[] {}, null, deploymentBytes, 0, m_messenger);
        return ((deployment.getCommandlog() != null) && (deployment.getCommandlog().isEnabled()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CatalogAndIds(org.voltdb.utils.CatalogUtil.CatalogAndIds) SecurityType(org.voltdb.compiler.deploymentfile.SecurityType) Cluster(org.voltdb.catalog.Cluster) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) 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) Catalog(org.voltdb.catalog.Catalog) DbSettings(org.voltdb.settings.DbSettings) HeartbeatType(org.voltdb.compiler.deploymentfile.HeartbeatType) ConsistencyType(org.voltdb.compiler.deploymentfile.ConsistencyType) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) SystemSettingsType(org.voltdb.compiler.deploymentfile.SystemSettingsType) ByteArrayInputStream(java.io.ByteArrayInputStream) PartitionDetectionType(org.voltdb.compiler.deploymentfile.PartitionDetectionType) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 2 with HeartbeatType

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

the class TestJSONInterface method testUpdateDeployment.

public void testUpdateDeployment() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("foo", "bar");
        builder.addProcedures(DelayProc.class);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        //Get deployment
        String jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        //POST deployment with no content
        String pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 400, "application/json", null);
        assertTrue(pdep.contains("Failed"));
        Map<String, String> params = new HashMap<>();
        params.put("deployment", jdep);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        assertTrue(pdep.contains("Deployment Updated"));
        //POST deployment in admin mode
        params.put("admin", "true");
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        assertTrue(pdep.contains("Deployment Updated"));
        ObjectMapper mapper = new ObjectMapper();
        DeploymentType deptype = mapper.readValue(jdep, DeploymentType.class);
        //Test change heartbeat.
        if (deptype.getHeartbeat() == null) {
            HeartbeatType hb = new HeartbeatType();
            hb.setTimeout(99);
            deptype.setHeartbeat(hb);
        } else {
            deptype.getHeartbeat().setTimeout(99);
        }
        String ndeptype = mapper.writeValueAsString(deptype);
        params.put("deployment", ndeptype);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        System.out.println("POST result is: " + pdep);
        assertTrue(pdep.contains("Deployment Updated"));
        jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        deptype = mapper.readValue(jdep, DeploymentType.class);
        int nto = deptype.getHeartbeat().getTimeout();
        assertEquals(99, nto);
        //Test change Query timeout
        SystemSettingsType ss = deptype.getSystemsettings();
        if (ss == null) {
            ss = new SystemSettingsType();
            deptype.setSystemsettings(ss);
        }
        Query qv = ss.getQuery();
        if (qv == null) {
            qv = new Query();
            qv.setTimeout(99);
        } else {
            qv.setTimeout(99);
        }
        ss.setQuery(qv);
        deptype.setSystemsettings(ss);
        ndeptype = mapper.writeValueAsString(deptype);
        params.put("deployment", ndeptype);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        System.out.println("POST result is: " + pdep);
        assertTrue(pdep.contains("Deployment Updated"));
        jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        deptype = mapper.readValue(jdep, DeploymentType.class);
        nto = deptype.getSystemsettings().getQuery().getTimeout();
        assertEquals(99, nto);
        qv.setTimeout(88);
        ss.setQuery(qv);
        deptype.setSystemsettings(ss);
        ndeptype = mapper.writeValueAsString(deptype);
        params.put("deployment", ndeptype);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        System.out.println("POST result is: " + pdep);
        assertTrue(pdep.contains("Deployment Updated"));
        jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        deptype = mapper.readValue(jdep, DeploymentType.class);
        nto = deptype.getSystemsettings().getQuery().getTimeout();
        assertEquals(88, nto);
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) Query(org.voltdb.compiler.deploymentfile.SystemSettingsType.Query) HashMap(java.util.HashMap) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) HeartbeatType(org.voltdb.compiler.deploymentfile.HeartbeatType) SystemSettingsType(org.voltdb.compiler.deploymentfile.SystemSettingsType) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with HeartbeatType

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

the class VoltProjectBuilder method writeDeploymentFile.

/**
     * Writes deployment.xml file to a temporary file. It is constructed from the passed parameters and the m_users
     * field.
     *
     * @param voltRoot
     * @param dinfo an instance {@link DeploymentInfo}
     * @return deployment path
     * @throws IOException
     * @throws JAXBException
     */
private String writeDeploymentFile(String voltRoot, DeploymentInfo dinfo) throws IOException, JAXBException {
    org.voltdb.compiler.deploymentfile.ObjectFactory factory = new org.voltdb.compiler.deploymentfile.ObjectFactory();
    // <deployment>
    DeploymentType deployment = factory.createDeploymentType();
    JAXBElement<DeploymentType> doc = factory.createDeployment(deployment);
    // <cluster>
    ClusterType cluster = factory.createClusterType();
    deployment.setCluster(cluster);
    cluster.setHostcount(dinfo.hostCount);
    cluster.setSitesperhost(dinfo.sitesPerHost);
    cluster.setKfactor(dinfo.replication);
    cluster.setId(dinfo.clusterId);
    cluster.setSchema(m_useDDLSchema ? SchemaType.DDL : SchemaType.CATALOG);
    // <paths>
    PathsType paths = factory.createPathsType();
    deployment.setPaths(paths);
    if ((voltRoot != null) && !voltRoot.trim().isEmpty()) {
        Voltdbroot voltdbroot = factory.createPathsTypeVoltdbroot();
        paths.setVoltdbroot(voltdbroot);
        voltdbroot.setPath(voltRoot);
    }
    if (m_snapshotPath != null) {
        PathsType.Snapshots snapshotPathElement = factory.createPathsTypeSnapshots();
        snapshotPathElement.setPath(m_snapshotPath);
        paths.setSnapshots(snapshotPathElement);
    }
    if (m_deadHostTimeout != null) {
        HeartbeatType heartbeat = factory.createHeartbeatType();
        heartbeat.setTimeout(m_deadHostTimeout);
        deployment.setHeartbeat(heartbeat);
    }
    if (m_commandLogPath != null) {
        PathsType.Commandlog commandLogPathElement = factory.createPathsTypeCommandlog();
        commandLogPathElement.setPath(m_commandLogPath);
        paths.setCommandlog(commandLogPathElement);
    }
    if (m_internalSnapshotPath != null) {
        PathsType.Commandlogsnapshot commandLogSnapshotPathElement = factory.createPathsTypeCommandlogsnapshot();
        commandLogSnapshotPathElement.setPath(m_internalSnapshotPath);
        paths.setCommandlogsnapshot(commandLogSnapshotPathElement);
    }
    if (m_snapshotPrefix != null) {
        SnapshotType snapshot = factory.createSnapshotType();
        deployment.setSnapshot(snapshot);
        snapshot.setFrequency(m_snapshotFrequency);
        snapshot.setPrefix(m_snapshotPrefix);
        snapshot.setRetain(m_snapshotRetain);
    }
    SecurityType security = factory.createSecurityType();
    deployment.setSecurity(security);
    security.setEnabled(m_securityEnabled);
    SecurityProviderString provider = SecurityProviderString.HASH;
    if (m_securityEnabled)
        try {
            provider = SecurityProviderString.fromValue(m_securityProvider);
        } catch (IllegalArgumentException shouldNotHappenSeeSetter) {
        }
    security.setProvider(provider);
    // set the command log (which defaults to off)
    CommandLogType commandLogType = factory.createCommandLogType();
    commandLogType.setEnabled(m_commandLogEnabled);
    if (m_commandLogSync != null) {
        commandLogType.setSynchronous(m_commandLogSync.booleanValue());
    }
    if (m_commandLogSize != null) {
        commandLogType.setLogsize(m_commandLogSize);
    }
    if (m_commandLogFsyncInterval != null || m_commandLogMaxTxnsBeforeFsync != null) {
        CommandLogType.Frequency frequency = factory.createCommandLogTypeFrequency();
        if (m_commandLogFsyncInterval != null) {
            frequency.setTime(m_commandLogFsyncInterval);
        }
        if (m_commandLogMaxTxnsBeforeFsync != null) {
            frequency.setTransactions(m_commandLogMaxTxnsBeforeFsync);
        }
        commandLogType.setFrequency(frequency);
    }
    deployment.setCommandlog(commandLogType);
    // <partition-detection>/<snapshot>
    PartitionDetectionType ppd = factory.createPartitionDetectionType();
    deployment.setPartitionDetection(ppd);
    ppd.setEnabled(m_ppdEnabled);
    // don't include this element if not explicitly set
    if (m_heartbeatTimeout != null) {
        HeartbeatType hb = factory.createHeartbeatType();
        deployment.setHeartbeat(hb);
        hb.setTimeout((int) m_heartbeatTimeout);
    }
    // don't include this element if not explicitly set
    if (m_consistencyReadLevel != null) {
        ConsistencyType ct = factory.createConsistencyType();
        deployment.setConsistency(ct);
        ct.setReadlevel(m_consistencyReadLevel.toReadLevelType());
    }
    deployment.setSystemsettings(createSystemSettingsType(factory));
    // <users>
    if (m_users.size() > 0) {
        UsersType users = factory.createUsersType();
        deployment.setUsers(users);
        // <user>
        for (final UserInfo info : m_users) {
            User user = factory.createUsersTypeUser();
            users.getUser().add(user);
            user.setName(info.name);
            user.setPassword(info.password);
            user.setPlaintext(info.plaintext);
            // build up user/roles.
            if (info.roles.length > 0) {
                final StringBuilder roles = new StringBuilder();
                for (final String role : info.roles) {
                    if (roles.length() > 0)
                        roles.append(",");
                    roles.append(role);
                }
                user.setRoles(roles.toString());
            }
        }
    }
    SslType ssl = factory.createSslType();
    deployment.setSsl(ssl);
    ssl.setEnabled(m_sslEnabled);
    ssl.setExternal(m_sslExternal);
    if (m_keystore != null) {
        KeyOrTrustStoreType store = factory.createKeyOrTrustStoreType();
        store.setPath(m_keystore);
        store.setPassword(m_keystorePassword);
        ssl.setKeystore(store);
    }
    if (m_certstore != null) {
        KeyOrTrustStoreType store = factory.createKeyOrTrustStoreType();
        store.setPath(m_certstore);
        store.setPassword(m_certstorePassword);
        ssl.setTruststore(store);
    }
    // <httpd>. Disabled unless port # is configured by a testcase
    // Omit element(s) when null.
    HttpdType httpd = factory.createHttpdType();
    deployment.setHttpd(httpd);
    httpd.setEnabled(m_httpdPortNo != -1);
    httpd.setPort(m_httpdPortNo);
    Jsonapi json = factory.createHttpdTypeJsonapi();
    httpd.setJsonapi(json);
    json.setEnabled(m_jsonApiEnabled);
    //SNMP
    SnmpType snmpType = factory.createSnmpType();
    if (m_snmpEnabled) {
        snmpType.setEnabled(true);
        snmpType.setTarget(m_snmpTarget);
        deployment.setSnmp(snmpType);
    }
    // <export>
    ExportType export = factory.createExportType();
    deployment.setExport(export);
    for (HashMap<String, Object> exportConnector : m_elExportConnectors) {
        ExportConfigurationType exportConfig = factory.createExportConfigurationType();
        exportConfig.setEnabled((boolean) exportConnector.get("elEnabled") && exportConnector.get("elLoader") != null && !((String) exportConnector.get("elLoader")).trim().isEmpty());
        ServerExportEnum exportTarget = ServerExportEnum.fromValue(((String) exportConnector.get("elExportTarget")).toLowerCase());
        exportConfig.setType(exportTarget);
        if (exportTarget.equals(ServerExportEnum.CUSTOM)) {
            exportConfig.setExportconnectorclass(System.getProperty(ExportDataProcessor.EXPORT_TO_TYPE));
        }
        exportConfig.setTarget((String) exportConnector.get("elGroup"));
        Properties config = (Properties) exportConnector.get("elConfig");
        if ((config != null) && (config.size() > 0)) {
            List<PropertyType> configProperties = exportConfig.getProperty();
            for (Object nameObj : config.keySet()) {
                String name = String.class.cast(nameObj);
                PropertyType prop = factory.createPropertyType();
                prop.setName(name);
                prop.setValue(config.getProperty(name));
                configProperties.add(prop);
            }
        }
        export.getConfiguration().add(exportConfig);
    }
    // <import>
    ImportType importt = factory.createImportType();
    deployment.setImport(importt);
    for (HashMap<String, Object> importConnector : m_ilImportConnectors) {
        ImportConfigurationType importConfig = factory.createImportConfigurationType();
        importConfig.setEnabled((boolean) importConnector.get("ilEnabled"));
        ServerImportEnum importType = ServerImportEnum.fromValue(((String) importConnector.get("ilImportType")).toLowerCase());
        importConfig.setType(importType);
        importConfig.setModule((String) importConnector.get("ilModule"));
        String formatter = (String) importConnector.get("ilFormatter");
        if (formatter != null) {
            importConfig.setFormat(formatter);
        }
        Properties config = (Properties) importConnector.get("ilConfig");
        if ((config != null) && (config.size() > 0)) {
            List<PropertyType> configProperties = importConfig.getProperty();
            for (Object nameObj : config.keySet()) {
                String name = String.class.cast(nameObj);
                PropertyType prop = factory.createPropertyType();
                prop.setName(name);
                prop.setValue(config.getProperty(name));
                configProperties.add(prop);
            }
        }
        Properties formatConfig = (Properties) importConnector.get("ilFormatterConfig");
        if ((formatConfig != null) && (formatConfig.size() > 0)) {
            List<PropertyType> configProperties = importConfig.getFormatProperty();
            for (Object nameObj : formatConfig.keySet()) {
                String name = String.class.cast(nameObj);
                PropertyType prop = factory.createPropertyType();
                prop.setName(name);
                prop.setValue(formatConfig.getProperty(name));
                configProperties.add(prop);
            }
        }
        importt.getConfiguration().add(importConfig);
    }
    DrType dr = factory.createDrType();
    deployment.setDr(dr);
    dr.setListen(m_drProducerEnabled);
    dr.setRole(m_drRole);
    if (m_drMasterHost != null && !m_drMasterHost.isEmpty()) {
        ConnectionType conn = factory.createConnectionType();
        dr.setConnection(conn);
        conn.setSource(m_drMasterHost);
        conn.setPreferredSource(m_preferredSource);
        conn.setEnabled(m_drConsumerConnectionEnabled);
    }
    // Have some yummy boilerplate!
    File file = File.createTempFile("myAppDeployment", ".tmp");
    JAXBContext context = JAXBContext.newInstance(DeploymentType.class);
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(doc, file);
    final String deploymentPath = file.getPath();
    return deploymentPath;
}
Also used : Jsonapi(org.voltdb.compiler.deploymentfile.HttpdType.Jsonapi) SecurityProviderString(org.voltdb.compiler.deploymentfile.SecurityProviderString) PropertyType(org.voltdb.compiler.deploymentfile.PropertyType) PartitionDetectionType(org.voltdb.compiler.deploymentfile.PartitionDetectionType) ConnectionType(org.voltdb.compiler.deploymentfile.ConnectionType) Voltdbroot(org.voltdb.compiler.deploymentfile.PathsType.Voltdbroot) ServerExportEnum(org.voltdb.compiler.deploymentfile.ServerExportEnum) ExportConfigurationType(org.voltdb.compiler.deploymentfile.ExportConfigurationType) SslType(org.voltdb.compiler.deploymentfile.SslType) File(java.io.File) SecurityType(org.voltdb.compiler.deploymentfile.SecurityType) User(org.voltdb.compiler.deploymentfile.UsersType.User) SecurityProviderString(org.voltdb.compiler.deploymentfile.SecurityProviderString) JAXBContext(javax.xml.bind.JAXBContext) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) Properties(java.util.Properties) HeartbeatType(org.voltdb.compiler.deploymentfile.HeartbeatType) ConsistencyType(org.voltdb.compiler.deploymentfile.ConsistencyType) PathsType(org.voltdb.compiler.deploymentfile.PathsType) CommandLogType(org.voltdb.compiler.deploymentfile.CommandLogType) ImportType(org.voltdb.compiler.deploymentfile.ImportType) Marshaller(javax.xml.bind.Marshaller) ServerImportEnum(org.voltdb.compiler.deploymentfile.ServerImportEnum) ExportType(org.voltdb.compiler.deploymentfile.ExportType) ClusterType(org.voltdb.compiler.deploymentfile.ClusterType) DrType(org.voltdb.compiler.deploymentfile.DrType) HttpdType(org.voltdb.compiler.deploymentfile.HttpdType) UsersType(org.voltdb.compiler.deploymentfile.UsersType) SnmpType(org.voltdb.compiler.deploymentfile.SnmpType) SnapshotType(org.voltdb.compiler.deploymentfile.SnapshotType) ImportConfigurationType(org.voltdb.compiler.deploymentfile.ImportConfigurationType) KeyOrTrustStoreType(org.voltdb.compiler.deploymentfile.KeyOrTrustStoreType)

Example 4 with HeartbeatType

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

the class CatalogUtil method populateDefaultDeployment.

public static void populateDefaultDeployment(DeploymentType deployment) {
    //partition detection
    PartitionDetectionType pd = deployment.getPartitionDetection();
    if (pd == null) {
        pd = new PartitionDetectionType();
        deployment.setPartitionDetection(pd);
    }
    //heartbeat
    if (deployment.getHeartbeat() == null) {
        HeartbeatType hb = new HeartbeatType();
        deployment.setHeartbeat(hb);
    }
    SslType ssl = deployment.getSsl();
    if (ssl == null) {
        ssl = new SslType();
        deployment.setSsl(ssl);
    }
    //httpd
    HttpdType httpd = deployment.getHttpd();
    if (httpd == null) {
        httpd = new HttpdType();
        // Find next available port starting with the default
        httpd.setPort(Constants.HTTP_PORT_AUTO);
        deployment.setHttpd(httpd);
    }
    //jsonApi
    HttpdType.Jsonapi jsonApi = httpd.getJsonapi();
    if (jsonApi == null) {
        jsonApi = new HttpdType.Jsonapi();
        httpd.setJsonapi(jsonApi);
    }
    //snapshot
    if (deployment.getSnapshot() == null) {
        SnapshotType snap = new SnapshotType();
        snap.setEnabled(false);
        deployment.setSnapshot(snap);
    }
    //Security
    if (deployment.getSecurity() == null) {
        SecurityType sec = new SecurityType();
        deployment.setSecurity(sec);
    }
    //Paths
    if (deployment.getPaths() == null) {
        PathsType paths = new PathsType();
        deployment.setPaths(paths);
    }
    //create paths entries
    PathsType paths = deployment.getPaths();
    if (paths.getVoltdbroot() == null) {
        PathsType.Voltdbroot root = new PathsType.Voltdbroot();
        paths.setVoltdbroot(root);
    }
    //snapshot
    if (paths.getSnapshots() == null) {
        PathsType.Snapshots snap = new PathsType.Snapshots();
        paths.setSnapshots(snap);
    }
    if (paths.getCommandlog() == null) {
        //cl
        PathsType.Commandlog cl = new PathsType.Commandlog();
        paths.setCommandlog(cl);
    }
    if (paths.getCommandlogsnapshot() == null) {
        //cl snap
        PathsType.Commandlogsnapshot clsnap = new PathsType.Commandlogsnapshot();
        paths.setCommandlogsnapshot(clsnap);
    }
    if (paths.getExportoverflow() == null) {
        //export overflow
        PathsType.Exportoverflow exp = new PathsType.Exportoverflow();
        paths.setExportoverflow(exp);
    }
    if (paths.getDroverflow() == null) {
        final PathsType.Droverflow droverflow = new PathsType.Droverflow();
        paths.setDroverflow(droverflow);
    }
    //Command log info
    if (deployment.getCommandlog() == null) {
        boolean enabled = false;
        if (MiscUtils.isPro()) {
            enabled = true;
        }
        CommandLogType cl = new CommandLogType();
        cl.setEnabled(enabled);
        Frequency freq = new Frequency();
        cl.setFrequency(freq);
        deployment.setCommandlog(cl);
    }
    //System settings
    SystemSettingsType ss = deployment.getSystemsettings();
    if (deployment.getSystemsettings() == null) {
        ss = new SystemSettingsType();
        deployment.setSystemsettings(ss);
    }
    SystemSettingsType.Elastic sse = ss.getElastic();
    if (sse == null) {
        sse = new SystemSettingsType.Elastic();
        ss.setElastic(sse);
    }
    SystemSettingsType.Query query = ss.getQuery();
    if (query == null) {
        query = new SystemSettingsType.Query();
        ss.setQuery(query);
    }
    SystemSettingsType.Snapshot snap = ss.getSnapshot();
    if (snap == null) {
        snap = new SystemSettingsType.Snapshot();
        ss.setSnapshot(snap);
    }
    SystemSettingsType.Temptables tt = ss.getTemptables();
    if (tt == null) {
        tt = new SystemSettingsType.Temptables();
        ss.setTemptables(tt);
    }
    ResourceMonitorType rm = ss.getResourcemonitor();
    if (rm == null) {
        rm = new ResourceMonitorType();
        ss.setResourcemonitor(rm);
    }
    ResourceMonitorType.Memorylimit mem = rm.getMemorylimit();
    if (mem == null) {
        mem = new ResourceMonitorType.Memorylimit();
        rm.setMemorylimit(mem);
    }
}
Also used : SecurityType(org.voltdb.compiler.deploymentfile.SecurityType) HeartbeatType(org.voltdb.compiler.deploymentfile.HeartbeatType) PathsType(org.voltdb.compiler.deploymentfile.PathsType) CommandLogType(org.voltdb.compiler.deploymentfile.CommandLogType) SystemSettingsType(org.voltdb.compiler.deploymentfile.SystemSettingsType) PartitionDetectionType(org.voltdb.compiler.deploymentfile.PartitionDetectionType) ResourceMonitorType(org.voltdb.compiler.deploymentfile.ResourceMonitorType) HttpdType(org.voltdb.compiler.deploymentfile.HttpdType) Frequency(org.voltdb.compiler.deploymentfile.CommandLogType.Frequency) SslType(org.voltdb.compiler.deploymentfile.SslType) SnapshotType(org.voltdb.compiler.deploymentfile.SnapshotType)

Aggregations

HeartbeatType (org.voltdb.compiler.deploymentfile.HeartbeatType)4 DeploymentType (org.voltdb.compiler.deploymentfile.DeploymentType)3 PartitionDetectionType (org.voltdb.compiler.deploymentfile.PartitionDetectionType)3 SecurityType (org.voltdb.compiler.deploymentfile.SecurityType)3 SystemSettingsType (org.voltdb.compiler.deploymentfile.SystemSettingsType)3 File (java.io.File)2 CommandLogType (org.voltdb.compiler.deploymentfile.CommandLogType)2 ConsistencyType (org.voltdb.compiler.deploymentfile.ConsistencyType)2 HttpdType (org.voltdb.compiler.deploymentfile.HttpdType)2 PathsType (org.voltdb.compiler.deploymentfile.PathsType)2 SnapshotType (org.voltdb.compiler.deploymentfile.SnapshotType)2 SslType (org.voltdb.compiler.deploymentfile.SslType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketException (java.net.SocketException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 JAXBContext (javax.xml.bind.JAXBContext)1