|
Glassfish example source code file (CreateLocalInstanceCommand.java)
The Glassfish CreateLocalInstanceCommand.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.enterprise.admin.cli.cluster; import com.sun.enterprise.admin.cli.CLIConstants; import com.sun.enterprise.admin.cli.remote.RemoteCommand; import com.sun.enterprise.admin.servermgmt.KeystoreManager; import com.sun.enterprise.admin.util.CommandModelData.ParamModelData; import com.sun.enterprise.security.store.PasswordAdapter; import com.sun.enterprise.util.OS; import com.sun.enterprise.util.SystemPropertyConstants; import org.glassfish.api.I18n; import org.glassfish.api.Param; import org.glassfish.api.admin.CommandException; import org.glassfish.api.admin.CommandValidationException; import org.jvnet.hk2.annotations.Scoped; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.component.PerLookup; import java.io.File; import java.io.IOException; import java.net.InetAddress; import java.net.URI; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * This is a local command that calls the primitive remote _register-instance to add the * entries in domain.xml and then the primitive local command _create-instance-filesystem * to create the empty directory structure and das.properties * */ @Service(name = "create-local-instance") @Scoped(PerLookup.class) @I18n("create.local.instance") public final class CreateLocalInstanceCommand extends CreateLocalInstanceFilesystemCommand { private final String CONFIG = "config"; private final String CLUSTER = "cluster"; @Param(name = CONFIG, optional = true) private String configName; @Param(name = CLUSTER, optional = true) private String clusterName; @Param(name="lbenabled", optional = true) private Boolean lbEnabled; @Param(name = "systemproperties", optional = true, separator = ':') private String systemProperties; // XXX - should it be a Properties? @Param(name = "portbase", optional = true) private String portBase; @Param(name = "checkports", optional = true, defaultValue = "true") private boolean checkPorts = true; @Param(name = "savemasterpassword", optional = true, defaultValue = "false") private boolean saveMasterPassword = false; @Param(name = "usemasterpassword", optional = true, defaultValue = "false") private boolean useMasterPassword = false; private String masterPassword = null; private static final String RENDEZVOUS_PROPERTY_NAME = "rendezvousOccurred"; private String INSTANCE_DOTTED_NAME; private String RENDEZVOUS_DOTTED_NAME; private boolean _rendezvousOccurred; private String _node; protected static final String DEFAULT_MASTER_PASSWORD = KeystoreManager.DEFAULT_MASTER_PASSWORD; private ParamModelData masterPasswordOption; private static final String MASTER_PASSWORD_ALIAS="master-password"; /** */ @Override protected void validate() throws CommandException { echoCommand(); if (configName != null && clusterName != null) { throw new CommandException( Strings.get("ConfigClusterConflict")); } if (lbEnabled != null && clusterName == null) { throw new CommandException( Strings.get("lbenabledNotForStandaloneInstance")); } setDasDefaultsOnly = true; //Issue 12847 - Call super.validate to setDasDefaults only super.validate(); //so _validate-node uses das host from das.properties. No dirs created. if (node != null) { validateNode(node, getProductRootPath(), getInstanceHostName(true)); } if (!rendezvousWithDAS()) { throw new CommandException( Strings.get("Instance.rendezvousFailed", DASHost, "" + DASPort)); } if (instanceName.equals(SystemPropertyConstants.DAS_SERVER_NAME)) { throw new CommandException( Strings.get("Instance.alreadyExists", SystemPropertyConstants.DAS_SERVER_NAME)); } setDomainName(); setDasDefaultsOnly = false; super.validate(); // instanceName is validated and set in super.validate(), directories created INSTANCE_DOTTED_NAME = "servers.server." + instanceName; RENDEZVOUS_DOTTED_NAME = INSTANCE_DOTTED_NAME + ".property." + RENDEZVOUS_PROPERTY_NAME; _rendezvousOccurred = rendezvousOccurred(); if (_rendezvousOccurred) { throw new CommandException( Strings.get("Instance.rendezvousAlready", instanceName)); } } /** */ @Override protected int executeCommand() throws CommandException, CommandValidationException { int exitCode = -1; if (node == null) { _node = nodeDirChild.getName(); String nodeHost = getInstanceHostName(true); createNodeImplicit(_node, getProductRootPath(), nodeHost); } else { _node = node; } if (isRegisteredToDAS()) { if (!_rendezvousOccurred) { setRendezvousOccurred("true"); _rendezvousOccurred = true; } } else { try { registerToDAS(); _rendezvousOccurred = true; } catch (CommandException ce) { instanceDir.delete(); throw ce; } } bootstrapSecureAdminFiles(); try { exitCode = super.executeCommand(); if (exitCode == SUCCESS) { saveMasterPassword(); } } catch (CommandException ce) { String msg = "Something went wrong in creating the local filesystem for instance " + instanceName; if (ce.getLocalizedMessage() != null) { msg = msg + ": " + ce.getLocalizedMessage(); } logger.severe(msg); setRendezvousOccurred("false"); _rendezvousOccurred = false; throw new CommandException(msg, ce); } return exitCode; } private int bootstrapSecureAdminFiles() throws CommandException { RemoteCommand rc = new RemoteCommand("_bootstrap-secure-admin", this.programOpts, this.env); rc.setFileOutputDirectory(instanceDir); logger.finest("Download root for bootstrapping: " + instanceDir.getAbsolutePath()); final int result = rc.execute(new String[] {"_bootstrap-secure-admin"}); /* * The domain.xml just bootstrapped will look up-to-date compared to * the domain.xml on the DAS when this instance is started (if nothing * else happens in the meantime to change the DAS domain.xml timestamp). * That would fool the synchronization logic into thinking the instance * is up-to-date, whereas the instance will need to be sync-ed. * * So, adjust the just downloaded domain.xml's timestamp so it will * seem obsolete and trigger a sync when the instance is started. */ final URI domainXMLURI = URI.create("config/domain.xml"); final File domainXMLFile = new File(instanceDir.toURI().resolve(domainXMLURI)); domainXMLFile.setLastModified(0); return result; } /** * If --savemasterpassword=true, * then --usemasterpassword is set to true also * If AS_ADMIN_MASTERPASSWORD from --passwordfile exists that is used. * If it does not exist, the user is asked to enter the master password. * The password is validated against the keystore if it exists. If successful, master-password * is saved to the server instance directory <glassfish-install>/nodes/ Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish CreateLocalInstanceCommand.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.