Search in sources :

Example 26 with DeploymentType

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

the class TestCatalogUtil method testDRConnection.

public void testDRConnection() throws Exception {
    final String multipleConnections = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='1'/>" + "    <dr>" + "        <connection source='master'/>" + "        <connection source='imposter'/>" + "    </dr>" + "</deployment>";
    final String oneConnection = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='1'/>" + "    <dr>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String oneEnabledConnection = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='1'/>" + "    <dr>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String drDisabled = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='1'/>" + "    <dr listen='false'>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String clusterIdTooSmall = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='-1'/>" + "    <dr>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String clusterIdTooLarge = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='128'/>" + "    <dr>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String twoClusterIds = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='5'/>" + "    <dr id='5'>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String twoConflictingClusterIds = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='5'/>" + "    <dr id='2'>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String drEnabledNoConnection = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='0'/>" + "    <dr listen='true'>" + "    </dr>" + "</deployment>";
    final String drEnabledWithEnabledConnection = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='1'/>" + "    <dr listen='true'>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final String drEnabledWithPort = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2' id='1'/>" + "    <dr listen='true' port='100'>" + "        <connection source='master'/>" + "    </dr>" + "</deployment>";
    final File tmpInvalidMultiple = VoltProjectBuilder.writeStringToTempFile(multipleConnections);
    assertNull(CatalogUtil.getDeployment(new FileInputStream(tmpInvalidMultiple)));
    final File tmpLowClusterId = VoltProjectBuilder.writeStringToTempFile(clusterIdTooSmall);
    assertNull(CatalogUtil.getDeployment(new FileInputStream(tmpLowClusterId)));
    final File tmpHighClusterId = VoltProjectBuilder.writeStringToTempFile(clusterIdTooLarge);
    assertNull(CatalogUtil.getDeployment(new FileInputStream(tmpHighClusterId)));
    assertTrue(catalog.getClusters().get("cluster").getDrmasterhost().isEmpty());
    assertFalse(catalog.getClusters().get("cluster").getDrproducerenabled());
    assertTrue(catalog.getClusters().get("cluster").getDeployment().isEmpty());
    final File tmpDefault = VoltProjectBuilder.writeStringToTempFile(oneConnection);
    DeploymentType valid_deployment = CatalogUtil.getDeployment(new FileInputStream(tmpDefault));
    assertNotNull(valid_deployment);
    String msg = CatalogUtil.compileDeployment(catalog, valid_deployment, false);
    assertTrue("Deployment file failed to parse", msg == null);
    assertEquals("master", catalog.getClusters().get("cluster").getDrmasterhost());
    assertTrue(catalog.getClusters().get("cluster").getDrproducerenabled());
    assertTrue(catalog.getClusters().get("cluster").getDrclusterid() == 1);
    final File tmpEnabled = VoltProjectBuilder.writeStringToTempFile(oneEnabledConnection);
    DeploymentType valid_deployment_enabled = CatalogUtil.getDeployment(new FileInputStream(tmpEnabled));
    assertNotNull(valid_deployment_enabled);
    setUp();
    msg = CatalogUtil.compileDeployment(catalog, valid_deployment_enabled, false);
    assertTrue("Deployment file failed to parse", msg == null);
    assertEquals("master", catalog.getClusters().get("cluster").getDrmasterhost());
    assertTrue(catalog.getClusters().get("cluster").getDrproducerenabled());
    assertTrue(catalog.getClusters().get("cluster").getDrclusterid() == 1);
    final File tmpDisabled = VoltProjectBuilder.writeStringToTempFile(drDisabled);
    DeploymentType valid_deployment_disabled = CatalogUtil.getDeployment(new FileInputStream(tmpDisabled));
    assertNotNull(valid_deployment_disabled);
    setUp();
    msg = CatalogUtil.compileDeployment(catalog, valid_deployment_disabled, false);
    assertTrue("Deployment file failed to parse", msg == null);
    assertFalse(catalog.getClusters().get("cluster").getDrmasterhost().isEmpty());
    assertFalse(catalog.getClusters().get("cluster").getDrproducerenabled());
    assertTrue(catalog.getClusters().get("cluster").getDrclusterid() == 1);
    final File tmpEnabledNoConn = VoltProjectBuilder.writeStringToTempFile(drEnabledNoConnection);
    DeploymentType valid_deployment_enabledNoConn = CatalogUtil.getDeployment(new FileInputStream(tmpEnabledNoConn));
    assertNotNull(valid_deployment_enabledNoConn);
    setUp();
    msg = CatalogUtil.compileDeployment(catalog, valid_deployment_enabledNoConn, false);
    assertTrue("Deployment file failed to parse", msg == null);
    assertTrue(catalog.getClusters().get("cluster").getDrmasterhost().isEmpty());
    assertTrue(catalog.getClusters().get("cluster").getDrproducerenabled());
    assertTrue(catalog.getClusters().get("cluster").getDrclusterid() == 0);
    final File tmpTwoClusterIds = VoltProjectBuilder.writeStringToTempFile(twoClusterIds);
    DeploymentType valid_deployment_twoClusterIds = CatalogUtil.getDeployment(new FileInputStream(tmpTwoClusterIds));
    assertNotNull(valid_deployment_twoClusterIds);
    setUp();
    msg = CatalogUtil.compileDeployment(catalog, valid_deployment_twoClusterIds, false);
    assertTrue("Deployment file failed to parse", msg == null);
    final File tmpTwoConflictingClusterIds = VoltProjectBuilder.writeStringToTempFile(twoConflictingClusterIds);
    DeploymentType invalid_deployment_twoConflictingClusterIds = CatalogUtil.getDeployment(new FileInputStream(tmpTwoConflictingClusterIds));
    assertNotNull(invalid_deployment_twoConflictingClusterIds);
    setUp();
    msg = CatalogUtil.compileDeployment(catalog, invalid_deployment_twoConflictingClusterIds, false);
    assertTrue("Deployment file failed to parse", msg != null);
    final File tmpEnabledWithConn = VoltProjectBuilder.writeStringToTempFile(drEnabledWithEnabledConnection);
    DeploymentType valid_deployment_enabledWithConn = CatalogUtil.getDeployment(new FileInputStream(tmpEnabledWithConn));
    assertNotNull(valid_deployment_enabledWithConn);
    setUp();
    msg = CatalogUtil.compileDeployment(catalog, valid_deployment_enabledWithConn, false);
    assertTrue("Deployment file failed to parse", msg == null);
    assertEquals("master", catalog.getClusters().get("cluster").getDrmasterhost());
    assertTrue(catalog.getClusters().get("cluster").getDrproducerenabled());
    assertTrue(catalog.getClusters().get("cluster").getDrclusterid() == 1);
    final File tmpEnabledWithPort = VoltProjectBuilder.writeStringToTempFile(drEnabledWithPort);
    DeploymentType valid_deployment_port = CatalogUtil.getDeployment(new FileInputStream(tmpEnabledWithPort));
    assertNotNull(valid_deployment_port);
    setUp();
    msg = CatalogUtil.compileDeployment(catalog, valid_deployment_port, false);
    assertTrue("Deployment file failed to parse", msg == null);
    assertFalse(catalog.getClusters().get("cluster").getDrmasterhost().isEmpty());
    assertTrue(catalog.getClusters().get("cluster").getDrproducerenabled());
    assertTrue(catalog.getClusters().get("cluster").getDrproducerport() == 100);
}
Also used : DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 27 with DeploymentType

use of org.voltdb.compiler.deploymentfile.DeploymentType 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)

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