Skip to content

Commit

Permalink
Additional cleanups - formatting, syntax, logging
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <[email protected]>
  • Loading branch information
dmatej committed Jan 19, 2025
1 parent 65201e4 commit cdbf8b8
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public String[] addJvmOptions(String[] options) throws InvalidJvmOptionException
}
final Set alreadyExist = new HashSet();
JvmOptionsElement last = last();
for (int i = 0; i < options.length; i++) {
if (!head.hasOption(options[i])) {
JvmOptionsElement x = new JvmOptionsElement(options[i]);
for (String option : options) {
if (!head.hasOption(option)) {
JvmOptionsElement x = new JvmOptionsElement(option);
last.setNext(x);
last = x;
} else {
alreadyExist.add(options[i]);
alreadyExist.add(option);
}
}
return toStringArray(alreadyExist);
Expand Down Expand Up @@ -115,9 +115,9 @@ public String[] deleteJvmOptions(String[] options) {
}

final Set donotExist = new HashSet();
for (int i = 0; i < options.length; i++) {
if (!head.deleteJvmOption(options[i])) {
donotExist.add(options[i]);
for (String option : options) {
if (!head.deleteJvmOption(option)) {
donotExist.add(option);
}
}
return toStringArray(donotExist);
Expand Down Expand Up @@ -209,6 +209,7 @@ void setNext(JvmOptionsElement element) {
throw new UnsupportedOperationException();
}
};

private final Set jvmOptions = new LinkedHashSet();
private JvmOptionsElement next;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -24,6 +25,7 @@
import jakarta.inject.Inject;

import java.io.File;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -86,15 +88,12 @@ public void execute(AdminCommandContext context) {
TokenResolver resolver = null;

// Create a resolver that can replace system properties in strings
Map<String, String> systemPropsMap =
new HashMap<String, String>((Map)(System.getProperties()));
Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
resolver = new TokenResolver(systemPropsMap);
String resolvedInstallDir = resolver.resolve(installdir);
File actualInstallDir = new File( resolvedInstallDir+"/" + NodeUtils.LANDMARK_FILE);


if (!actualInstallDir.exists()){
report.setMessage(Strings.get("invalid.installdir",installdir));
Path resolvedInstallDir = new File(resolver.resolve(installdir)).toPath();
Path actualInstallDir = resolvedInstallDir.resolve(NodeUtils.LANDMARK_FILE);
if (!actualInstallDir.toFile().exists()) {
report.setMessage(Strings.get("invalid.installdir", installdir));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Expand All @@ -103,12 +102,15 @@ public void execute(AdminCommandContext context) {
CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
ParameterMap map = new ParameterMap();
map.add("DEFAULT", name);
if (StringUtils.ok(nodedir))
if (StringUtils.ok(nodedir)) {
map.add(NodeUtils.PARAM_NODEDIR, nodedir);
if (StringUtils.ok(installdir))
}
if (StringUtils.ok(installdir)) {
map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
if (StringUtils.ok(nodehost))
}
if (StringUtils.ok(nodehost)) {
map.add(NodeUtils.PARAM_NODEHOST, nodehost);
}
map.add(NodeUtils.PARAM_TYPE,"CONFIG");
ci.parameters(map);
ci.execute();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -29,6 +30,7 @@

import java.beans.PropertyVetoException;
import java.io.File;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
Expand Down Expand Up @@ -99,20 +101,20 @@ public class UpdateNodeCommand implements AdminCommand {
@Param(name="sshnodehost", optional=true)
String sshnodehost;

@Param(name="sshkeyfile", optional=true)
@Param(name = "sshkeyfile", optional = true)
String sshkeyfile;

@Param(name = "sshpassword", optional = true, password=true)
String sshpassword;
@Param(name = "sshpassword", optional = true, password = true)
String sshpassword;

@Param(name = "sshkeypassphrase", optional = true, password=true)
String sshkeypassphrase;
@Param(name = "sshkeypassphrase", optional = true, password = true)
String sshkeypassphrase;

@Param(name = "windowsdomain", optional = true)
String windowsdomain;
String windowsdomain;

@Param(name = "type", optional=true)
String type;
@Param(name = "type", optional = true)
String type;

@Override
public void execute(AdminCommandContext context) {
Expand All @@ -134,15 +136,12 @@ public void execute(AdminCommandContext context) {
TokenResolver resolver = null;

// Create a resolver that can replace system properties in strings
Map<String, String> systemPropsMap =
new HashMap<String, String>((Map)(System.getProperties()));
Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
resolver = new TokenResolver(systemPropsMap);
String resolvedInstallDir = resolver.resolve(installdir);
File actualInstallDir = new File( resolvedInstallDir+"/" + NodeUtils.LANDMARK_FILE);


if (!actualInstallDir.exists()){
report.setMessage(Strings.get("invalid.installdir",installdir));
Path resolvedInstallDir = new File(resolver.resolve(installdir)).toPath();
Path actualInstallDir = resolvedInstallDir.resolve(NodeUtils.LANDMARK_FILE);
if (!actualInstallDir.toFile().exists()) {
report.setMessage(Strings.get("invalid.installdir", installdir));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Expand Down Expand Up @@ -195,43 +194,56 @@ public Object run(ConfigBeanProxy param) throws PropertyVetoException, Transacti
Nodes nodes = ((Domain)param).getNodes();
Node node = nodes.getNode(nodeName);
Node writeableNode = t.enroll(node);
if (windowsdomain != null)
if (windowsdomain != null) {
writeableNode.setWindowsDomain(windowsdomain);
if (nodedir != null)
}
if (nodedir != null) {
writeableNode.setNodeDir(nodedir);
if (nodehost != null)
}
if (nodehost != null) {
writeableNode.setNodeHost(nodehost);
if (installdir != null)
}
if (installdir != null) {
writeableNode.setInstallDir(installdir);
if (type != null)
}
if (type != null) {
writeableNode.setType(type);
}
if (sshport != null || sshnodehost != null ||sshuser != null || sshkeyfile != null){
SshConnector sshC = writeableNode.getSshConnector();
if (sshC == null) {
sshC =writeableNode.createChild(SshConnector.class);
}else
} else {
sshC = t.enroll(sshC);
}

if (sshport != null)
if (sshport != null) {
sshC.setSshPort(sshport);
if(sshnodehost != null)
}
if(sshnodehost != null) {
sshC.setSshHost(sshnodehost);
}

if (sshuser != null || sshkeyfile != null || sshpassword != null || sshkeypassphrase != null ) {
SshAuth sshA = sshC.getSshAuth();
if (sshA == null) {
sshA = sshC.createChild(SshAuth.class);
} else
} else {
sshA = t.enroll(sshA);
}

if (sshuser != null)
if (sshuser != null) {
sshA.setUserName(sshuser);
if (sshkeyfile != null)
}
if (sshkeyfile != null) {
sshA.setKeyfile(sshkeyfile);
if(sshpassword != null)
}
if(sshpassword != null) {
sshA.setPassword(sshpassword);
if(sshkeypassphrase != null)
}
if(sshkeypassphrase != null) {
sshA.setKeyPassphrase(sshkeypassphrase);
}
sshC.setSshAuth(sshA);
}
writeableNode.setSshConnector(sshC);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -13,7 +14,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.enterprise.admin.cli.cluster;

import com.sun.enterprise.util.net.NetUtils;
Expand Down Expand Up @@ -70,10 +70,11 @@ public class CreateLocalInstanceFilesystemCommand extends LocalInstanceCommand {
protected void validate()
throws CommandException {

if(ok(instanceName0))
if (ok(instanceName0)) {
instanceName = instanceName0;
else
} else {
throw new CommandException(Strings.get("Instance.badInstanceName"));
}

isCreateInstanceFilesystem = true;

Expand Down Expand Up @@ -108,8 +109,6 @@ protected void validate()

}

/**
*/
@Override
protected int executeCommand()
throws CommandException {
Expand Down Expand Up @@ -188,17 +187,15 @@ private void checkDASCoordinates() throws CommandException {
InetAddress.getByName(DASHost);
} catch (UnknownHostException e) {
String thisHost = NetUtils.getHostName();
String msg = Strings.get("Instance.DasHostUnknown",
DASHost, thisHost);
String msg = Strings.get("Instance.DasHostUnknown", DASHost, thisHost);
throw new CommandException(msg, e);
}

// See if DAS is reachable
if (! NetUtils.isRunning(DASHost, DASPort)) {
if (!NetUtils.isRunning(DASHost, DASPort)) {
// DAS provided host and port
String thisHost = NetUtils.getHostName();
String msg = Strings.get("Instance.DasHostUnreachable",
DASHost, Integer.toString(DASPort), thisHost);
String msg = Strings.get("Instance.DasHostUnreachable", DASHost, Integer.toString(DASPort), thisHost);
throw new CommandException(msg);
}
}
Expand Down
Loading

0 comments on commit cdbf8b8

Please sign in to comment.