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);
}
}
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;
}
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;
}
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();
}
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();
}
Aggregations