Search in sources :

Example 1 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class XmlClientConfigBuilder method handleAWS.

private void handleAWS(Node node, ClientNetworkConfig clientNetworkConfig) {
    ClientAwsConfig clientAwsConfig = handleAwsAttributes(node);
    for (Node n : childElements(node)) {
        String value = getTextContent(n).trim();
        if ("secret-key".equals(cleanNodeName(n))) {
            clientAwsConfig.setSecretKey(value);
        } else if ("access-key".equals(cleanNodeName(n))) {
            clientAwsConfig.setAccessKey(value);
        } else if ("region".equals(cleanNodeName(n))) {
            clientAwsConfig.setRegion(value);
        } else if ("host-header".equals(cleanNodeName(n))) {
            clientAwsConfig.setHostHeader(value);
        } else if ("security-group-name".equals(cleanNodeName(n))) {
            clientAwsConfig.setSecurityGroupName(value);
        } else if ("tag-key".equals(cleanNodeName(n))) {
            clientAwsConfig.setTagKey(value);
        } else if ("tag-value".equals(cleanNodeName(n))) {
            clientAwsConfig.setTagValue(value);
        } else if ("inside-aws".equals(cleanNodeName(n))) {
            clientAwsConfig.setInsideAws(getBooleanValue(value));
        } else if ("iam-role".equals(cleanNodeName(n))) {
            clientAwsConfig.setIamRole(value);
        }
    }
    if (!clientAwsConfig.isInsideAws() && clientAwsConfig.getIamRole() != null) {
        throw new InvalidConfigurationException("You cannot set IAM Role from outside EC2");
    }
    clientNetworkConfig.setAwsConfig(clientAwsConfig);
}
Also used : Node(org.w3c.dom.Node) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 2 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class XmlClientConfigBuilder method parse.

@Override
protected Document parse(InputStream inputStream) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    DocumentBuilder builder = dbf.newDocumentBuilder();
    try {
        return builder.parse(inputStream);
    } catch (Exception e) {
        String msg = "Failed to parse Config Stream" + LINE_SEPARATOR + "Exception: " + e.getMessage() + LINE_SEPARATOR + "HazelcastClient startup interrupted.";
        LOGGER.severe(msg);
        throw new InvalidConfigurationException(e.getMessage(), e);
    } finally {
        IOUtil.closeResource(inputStream);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) IOException(java.io.IOException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 3 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class ClientFailoverDomConfigProcessor method buildConfig.

@Override
public void buildConfig(Node rootNode) {
    for (Node node : childElements(rootNode)) {
        String nodeName = cleanNodeName(node);
        if (occurrenceSet.contains(nodeName)) {
            throw new InvalidConfigurationException("Duplicate '" + nodeName + "' definition found in the configuration");
        }
        handleNode(node, nodeName);
        if (!canOccurMultipleTimes(nodeName)) {
            occurrenceSet.add(nodeName);
        }
    }
}
Also used : Node(org.w3c.dom.Node) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 4 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class ClientFailoverDomConfigProcessor method handleClients.

protected void handleClients(Node node) {
    for (Node child : childElements(node)) {
        if (matches("client", cleanNodeName(child))) {
            String clientPath = getTextContent(child);
            try {
                ClientConfig config = new XmlClientConfigBuilder(clientPath).build();
                clientFailoverConfig.addClientConfig(config);
            } catch (IOException e) {
                throw new InvalidConfigurationException("Could not create the config from given path : " + clientPath, e);
            }
        }
    }
}
Also used : XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) Node(org.w3c.dom.Node) IOException(java.io.IOException) ClientConfig(com.hazelcast.client.config.ClientConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 5 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class YamlClientConfigBuilder method parseAndBuildConfig.

private void parseAndBuildConfig(ClientConfig config) throws Exception {
    YamlMapping yamlRootNode;
    try {
        yamlRootNode = ((YamlMapping) YamlLoader.load(in));
    } catch (Exception ex) {
        throw new InvalidConfigurationException("Invalid YAML configuration", ex);
    }
    YamlNode clientRoot = yamlRootNode.childAsMapping(ClientConfigSections.HAZELCAST_CLIENT.getName());
    if (clientRoot == null) {
        clientRoot = yamlRootNode;
    }
    YamlDomChecker.check(clientRoot);
    Node w3cRootNode = asW3cNode(clientRoot);
    replaceVariables(w3cRootNode);
    importDocuments(clientRoot);
    if (shouldValidateTheSchema()) {
        new YamlConfigSchemaValidator().validate((YamlMapping) clientRoot.parent());
    }
    new YamlClientDomConfigProcessor(true, config).buildConfig(w3cRootNode);
}
Also used : YamlConfigSchemaValidator(com.hazelcast.internal.config.YamlConfigSchemaValidator) YamlNode(com.hazelcast.internal.yaml.YamlNode) W3cDomUtil.asW3cNode(com.hazelcast.internal.config.yaml.W3cDomUtil.asW3cNode) Node(org.w3c.dom.Node) YamlNode(com.hazelcast.internal.yaml.YamlNode) YamlMapping(com.hazelcast.internal.yaml.YamlMapping) YamlClientDomConfigProcessor(com.hazelcast.client.config.impl.YamlClientDomConfigProcessor) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) IOException(java.io.IOException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)43 Node (org.w3c.dom.Node)19 YamlNode (com.hazelcast.internal.yaml.YamlNode)5 IOException (java.io.IOException)5 EvictionConfig (com.hazelcast.config.EvictionConfig)3 ValidationException (com.hazelcast.config.properties.ValidationException)3 YamlMapping (com.hazelcast.internal.yaml.YamlMapping)3 DiscoveryStrategy (com.hazelcast.spi.discovery.DiscoveryStrategy)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)2 Member (com.hazelcast.cluster.Member)2 EventJournalConfig (com.hazelcast.config.EventJournalConfig)2 EvictionPolicy (com.hazelcast.config.EvictionPolicy)2 MaxSizePolicy (com.hazelcast.config.MaxSizePolicy)2 OnJoinPermissionOperationName (com.hazelcast.config.OnJoinPermissionOperationName)2 PermissionType (com.hazelcast.config.PermissionConfig.PermissionType)2 PredicateConfig (com.hazelcast.config.PredicateConfig)2 WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)2 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)2 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)2