Search in sources :

Example 1 with DomainConfig

use of com.sun.enterprise.admin.servermgmt.DomainConfig in project Payara by payara.

the class CreateDomainCommand method createTheDomain.

/**
 * Create the domain.
 *
 * @param domainPath domain path to insert in domainConfig
 * @param domainProperties properties to insert in domainConfig
 * @throws CommandException if domain cannot be created
 */
private void createTheDomain(final String domainPath, Properties domainProperties) throws DomainException, CommandValidationException {
    // fix for bug# 4930684
    // domain name is validated before the ports
    String domainFilePath = (domainPath + File.separator + domainName);
    if (FileUtils.safeGetCanonicalFile(new File(domainFilePath)).exists()) {
        throw new CommandValidationException(STRINGS.get("DomainExists", domainName));
    }
    DomainConfig domainConfig = null;
    if (template == null || template.endsWith(".jar")) {
        domainConfig = new DomainConfig(domainName, domainPath, adminUser, adminPassword, masterPassword, saveMasterPassword, adminPort, instancePort, hazelcastDasPort, hazelcastStartPort, hazelcastAutoIncrement, domainProperties);
        domainConfig.put(K_VALIDATE_PORTS, checkPorts);
        domainConfig.put(KEYTOOLOPTIONS, keytoolOptions);
        domainConfig.put(K_TEMPLATE_NAME, template);
        domainConfig.put(K_PORTBASE, portBase);
        domainConfig.put(K_INITIAL_ADMIN_USER_GROUPS, Version.getInitialAdminGroups());
        initSecureAdminSettings(domainConfig);
        try {
            DomainBuilder domainBuilder = new DomainBuilder(domainConfig);
            domainBuilder.validateTemplate();
            domainBuilder.run();
        } catch (Exception e) {
            throw new DomainException(e.getMessage(), e);
        }
    } else {
        throw new DomainException(STRINGS.get("InvalidTemplateValue", template));
    }
    logger.info(STRINGS.get("DomainCreated", domainName));
    Integer aPort = (Integer) domainConfig.get(K_ADMIN_PORT);
    logger.info(STRINGS.get("DomainPort", domainName, Integer.toString(aPort)));
    if (adminPassword != null && adminPassword.equals(DEFAULT_ADMIN_PASSWORD)) {
        logger.info(STRINGS.get("DomainAllowsUnauth", domainName, adminUser));
    } else {
        logger.info(STRINGS.get("DomainAdminUser", domainName, adminUser));
    }
    if (saveLoginOpt) {
        saveLogin(aPort, adminUser, adminPassword != null ? adminPassword.toCharArray() : null, domainName);
    }
}
Also used : DomainBuilder(com.sun.enterprise.admin.servermgmt.domain.DomainBuilder) DomainException(com.sun.enterprise.admin.servermgmt.DomainException) CommandValidationException(org.glassfish.api.admin.CommandValidationException) File(java.io.File) CommandValidationException(org.glassfish.api.admin.CommandValidationException) EndOfFileException(org.jline.reader.EndOfFileException) DomainException(com.sun.enterprise.admin.servermgmt.DomainException) CommandException(org.glassfish.api.admin.CommandException) UserInterruptException(org.jline.reader.UserInterruptException) DomainConfig(com.sun.enterprise.admin.servermgmt.DomainConfig)

Example 2 with DomainConfig

use of com.sun.enterprise.admin.servermgmt.DomainConfig in project Payara by payara.

the class CreateDomainCommand method executeCommand.

@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    // Domain validation upfront (i.e. before we prompt)
    try {
        DomainsManager manager = new PEDomainsManager();
        DomainConfig config = new DomainConfig(domainName, domainDir);
        manager.validateDomain(config, false);
        verifyPortBase();
    } catch (DomainException e) {
        throw new CommandException(STRINGS.get("CouldNotCreateDomain", domainName), e);
    }
    /*
         * The admin user is specified with the --user program option. If not specified (because the user hit Enter at the
         * prompt), we use the default, which allows unauthenticated login.
         */
    adminUser = programOpts.getUser();
    if (!ok(adminUser)) {
        adminUser = DEFAULT_ADMIN_USER;
        adminPassword = DEFAULT_ADMIN_PASSWORD;
    } else if (noPassword) {
        adminPassword = DEFAULT_ADMIN_PASSWORD;
    } else {
        char[] pwdArr = getAdminPassword();
        adminPassword = pwdArr != null ? new String(pwdArr) : null;
    }
    if (saveMasterPassword) {
        useMasterPassword = true;
    }
    if (masterPassword == null) {
        if (useMasterPassword) {
            char[] mpArr = getMasterPassword();
            masterPassword = mpArr != null ? new String(mpArr) : null;
        } else {
            masterPassword = DEFAULT_MASTER_PASSWORD;
        }
    }
    try {
        // Verify admin port is valid if specified on command line
        if (adminPort != null) {
            verifyPortIsValid(adminPort);
        }
        if (hazelcastDasPort != null) {
            verifyPortIsValid(hazelcastDasPort);
        }
        if (hazelcastStartPort != null) {
            verifyPortIsValid(hazelcastStartPort);
        }
        // Instance option is entered then verify instance port is valid
        if (instancePort != null) {
            verifyPortIsValid(instancePort);
        }
        // Saving the login information happens inside this method
        createTheDomain(domainDir, domainProperties);
    } catch (Exception e) {
        throw new CommandException(STRINGS.get("CouldNotCreateDomain", domainName), e);
    }
    return 0;
}
Also used : DomainException(com.sun.enterprise.admin.servermgmt.DomainException) PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) DomainsManager(com.sun.enterprise.admin.servermgmt.DomainsManager) CommandException(org.glassfish.api.admin.CommandException) PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) CommandValidationException(org.glassfish.api.admin.CommandValidationException) EndOfFileException(org.jline.reader.EndOfFileException) DomainException(com.sun.enterprise.admin.servermgmt.DomainException) CommandException(org.glassfish.api.admin.CommandException) UserInterruptException(org.jline.reader.UserInterruptException) DomainConfig(com.sun.enterprise.admin.servermgmt.DomainConfig)

Example 3 with DomainConfig

use of com.sun.enterprise.admin.servermgmt.DomainConfig in project Payara by payara.

the class DeleteDomainCommand method executeCommand.

@Override
protected int executeCommand() throws CommandException {
    try {
        DomainConfig domainConfig = new DomainConfig(getDomainName(), getDomainsDir().getPath());
        checkRunning();
        checkRename();
        DomainsManager manager = new PEDomainsManager();
        manager.deleteDomain(domainConfig);
    // By default, do as what v2 does -- don't delete the entry -
    // might need a revisit (Kedar: 09/16/2009)
    // deleteLoginInfo();
    } catch (Exception e) {
        throw new CommandException(e.getLocalizedMessage());
    }
    logger.fine(STRINGS.get("DomainDeleted", getDomainName()));
    return 0;
}
Also used : PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) DomainsManager(com.sun.enterprise.admin.servermgmt.DomainsManager) PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) IOException(java.io.IOException) DomainConfig(com.sun.enterprise.admin.servermgmt.DomainConfig)

Example 4 with DomainConfig

use of com.sun.enterprise.admin.servermgmt.DomainConfig in project Payara by payara.

the class TestDomainPortValidator method testForNonNumericPort.

@Test(expectedExceptions = DomainException.class)
public void testForNonNumericPort() throws Exception {
    DomainConfig domainConfig = new DomainConfig("test", null);
    domainConfig.add(DomainConfig.K_VALIDATE_PORTS, Boolean.TRUE);
    domainConfig.add(DomainConfig.K_ADMIN_PORT, "admin2");
    _portValidator = new DomainPortValidator(domainConfig, new Properties());
    _portValidator.validateAndSetPorts();
}
Also used : Properties(java.util.Properties) DomainConfig(com.sun.enterprise.admin.servermgmt.DomainConfig) Test(org.testng.annotations.Test)

Example 5 with DomainConfig

use of com.sun.enterprise.admin.servermgmt.DomainConfig in project Payara by payara.

the class TestDomainPortValidator method testForMaxPort.

@Test(expectedExceptions = DomainException.class)
public void testForMaxPort() throws Exception {
    DomainConfig domainConfig = new DomainConfig("test", null);
    domainConfig.add(DomainConfig.K_VALIDATE_PORTS, Boolean.TRUE);
    domainConfig.add(DomainConfig.K_ADMIN_PORT, String.valueOf((DomainPortValidator.PORT_MAX_VAL + 1)));
    _portValidator = new DomainPortValidator(domainConfig, new Properties());
    _portValidator.validateAndSetPorts();
}
Also used : Properties(java.util.Properties) DomainConfig(com.sun.enterprise.admin.servermgmt.DomainConfig) Test(org.testng.annotations.Test)

Aggregations

DomainConfig (com.sun.enterprise.admin.servermgmt.DomainConfig)12 PEDomainsManager (com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager)6 DomainsManager (com.sun.enterprise.admin.servermgmt.DomainsManager)5 Properties (java.util.Properties)5 Test (org.testng.annotations.Test)5 File (java.io.File)4 DomainException (com.sun.enterprise.admin.servermgmt.DomainException)3 IOException (java.io.IOException)3 CommandException (org.glassfish.api.admin.CommandException)3 CommandValidationException (org.glassfish.api.admin.CommandValidationException)2 EndOfFileException (org.jline.reader.EndOfFileException)2 UserInterruptException (org.jline.reader.UserInterruptException)2 DomainBuilder (com.sun.enterprise.admin.servermgmt.domain.DomainBuilder)1 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 HostAndPort (com.sun.enterprise.util.HostAndPort)1 HashMap (java.util.HashMap)1 XMLStreamException (javax.xml.stream.XMLStreamException)1