Skip to content

Commit

Permalink
Merge branch 'cleanup2' into 'main'
Browse files Browse the repository at this point in the history
Cleanup errors and warnings

See merge request weblogic-cloud/weblogic-kubernetes-operator!4515
  • Loading branch information
rjeberhard committed Nov 28, 2023
2 parents 3f92cc6 + 0c514c0 commit 124ec36
Show file tree
Hide file tree
Showing 233 changed files with 3,715 additions and 4,442 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, Oracle and/or its affiliates.
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.kubernetes.common.logging;
Expand All @@ -22,6 +22,7 @@ public abstract class BaseLoggingFacade {
* Construct logging facade.
* @param logger logger
*/
@SuppressWarnings("this-escape")
protected BaseLoggingFacade(Logger logger) {
this.logger = logger;

Expand Down Expand Up @@ -245,7 +246,7 @@ public Level getLevel() {
/**
* Sets the level at which the underlying Logger operates. This should not be called in the
* general case; levels should be set via OOB configuration (a configuration file exposed by the
* logging implementation, management API, etc).
* logging implementation, management API, etc.).
*
* @param newLevel Level to set
*/
Expand Down Expand Up @@ -401,7 +402,7 @@ public boolean isWarningEnabled() {
* Logs a message at the requested level. Normally, one of the level-specific methods should be
* used instead.
*
* @param level Level at which log log the message
* @param level Level at which to log the message
* @param msg the message to log
*/
public void log(Level level, String msg) {
Expand All @@ -416,7 +417,7 @@ public void log(Level level, String msg) {
* param or an Object array, and is backward-compatible with them. Calling the per-Level methods
* is preferred, but this is present for completeness.
*
* @param level Level at which log log the message
* @param level Level at which to log the message
* @param msg the message to log
* @param params varargs list of objects to include in the log message
* @see Logger#log(java.util.logging.Level, String, Object[])
Expand All @@ -432,7 +433,7 @@ public void log(Level level, String msg, Object... params) {
* Logs a message which accompanies a Throwable. Calling equivalent per-Level method is preferred,
* but this is present for completeness.
*
* @param level Level at which log log the message
* @param level Level at which to log the message
* @param msg the message to log
* @param thrown an Exception to include in the logged message
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class BaseLoggingFormatter<T> extends Formatter {

@Override
public String format(LogRecord logRecord) {
String sourceClassName = "";
String sourceClassName;
String sourceMethodName = "";
if (logRecord.getSourceClassName() != null) {
sourceClassName = logRecord.getSourceClassName();
Expand Down Expand Up @@ -71,7 +71,7 @@ public String format(LogRecord logRecord) {
long rawTime = logRecord.getMillis();
final String dateString = DATE_FORMAT.format(OffsetDateTime.ofInstant(logRecord.getInstant(),
ZoneId.systemDefault()));
long thread = Thread.currentThread().getId();
long thread = Thread.currentThread().threadId();
T fiberObject = getCurrentFiberIfSet();

map.put(TIMESTAMP, dateString);
Expand All @@ -90,7 +90,7 @@ public String format(LogRecord logRecord) {
map.put(RESPONSE_CODE, code);
map.put(RESPONSE_HEADERS, headers);
map.put(RESPONSE_BODY, body.replace("\n", "\\\n"));
String json = "";
String json;
try {
ObjectMapper mapper = new ObjectMapper();
json = mapper.writeValueAsString(map);
Expand Down Expand Up @@ -123,7 +123,7 @@ protected T getCurrentFiberIfSet() {
protected abstract void processThrowable(LogRecord logRecord, ThrowableProcessing throwableProcessing);

protected class ThrowableProcessing {
private LogRecord logRecord;
private final LogRecord logRecord;
private String code;
private Map<String, List<String>> headers;
private String body;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, 2021, Oracle and/or its affiliates.
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.kubernetes.common.logging;
Expand All @@ -14,7 +14,7 @@ public interface LoggingFilter {
*
* @param loggingFilter LoggingFilter that decides whether the log message should be logged, can
* be null
* @param msg The log message to be loggd
* @param msg The log message to be logged
* @return the canLog() return value from the provided loggingFilter, message, and parameters, or
* true if loggingFilter is null
*/
Expand All @@ -26,7 +26,7 @@ static boolean canLog(LoggingFilter loggingFilter, String msg) {
* Checks if the message should be logged.
*
* @param msg the message to be logged
* @return true, if can log
* @return true, if the can log
*/
boolean canLog(String msg);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ public class MessageKeys {
public static final String ENABLED_FEATURES = "WLSKO-0003";
public static final String OPERATOR_SHUTTING_DOWN = "WLSKO-0005";
public static final String EXCEPTION = "WLSKO-0006";
public static final String NO_FORMATTING = "WLSKO-0007";
public static final String CREATING_CRD = "WLSKO-0012";
public static final String SECRET_NOT_FOUND = "WLSKO-0018";
public static final String RETRIEVING_SECRET = "WLSKO-0019";
public static final String SECRET_DATA_NOT_FOUND = "WLSKO-0020";
public static final String WLS_CONFIGURATION_READ = "WLSKO-0021";
public static final String JSON_PARSING_FAILED = "WLSKO-0026";
public static final String NO_WLS_SERVER_IN_CLUSTER = "WLSKO-0028";
public static final String VERIFY_ACCESS_START = "WLSKO-0029";
public static final String VERIFY_ACCESS_DENIED = "WLSKO-0030";
Expand Down Expand Up @@ -89,7 +86,6 @@ public class MessageKeys {
public static final String ADMIN_POD_PATCHED = "WLSKO-0120";
public static final String MANAGED_POD_PATCHED = "WLSKO-0121";
public static final String POD_DELETED = "WLSKO-0122";
public static final String TUNING_PARAMETERS = "WLSKO-0126";
public static final String WLS_HEALTH_READ_FAILED = "WLSKO-0127";
public static final String WLS_SERVER_TEMPLATE_NOT_FOUND = "WLSKO-0133";
public static final String SCRIPT_LOADED = "WLSKO-0134";
Expand All @@ -101,7 +97,6 @@ public class MessageKeys {
public static final String CANNOT_PARSE_TOPOLOGY = "WLSKO-0141";
public static final String CANNOT_PARSE_INTROSPECTOR_RESULT = "WLSKO-0142";
public static final String CANNOT_PARSE_INTROSPECTOR_FILE = "WLSKO-0143";
public static final String CANNOT_START_DOMAIN_AFTER_MAX_RETRIES = "WLSKO-0144";
public static final String CYCLING_POD = "WLSKO-0145";
public static final String REPLICAS_EXCEEDS_TOTAL_CLUSTER_SERVER_COUNT = "WLSKO-0146";
public static final String POD_DUMP = "WLSKO-0148";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class CommonUtils {

private static CheckedFunction<String, String> getMD5Hash = CommonUtils::getMD5Hash;
private static final CheckedFunction<String, String> getMD5Hash = CommonUtils::getMD5Hash;

public static final int MAX_ALLOWED_VOLUME_NAME_LENGTH = 63;
public static final String VOLUME_NAME_SUFFIX = "-volume";
Expand Down Expand Up @@ -78,7 +78,7 @@ private static String getShortName(String resourceName) throws NoSuchAlgorithmEx
* Gets the MD5 hash of a string.
*
* @param data input string
* @return MD5 hash value of the data, null in case of an exception.
* @return MD5 hash value of the data
*/
public static String getMD5Hash(String data) throws NoSuchAlgorithmException {
return bytesToHex(MessageDigest.getInstance("MD5").digest(data.getBytes(StandardCharsets.UTF_8)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,7 @@ public interface ResourceLookup {
List<Map<String, Object>> listClusters();
}

public static class Resources {
public final Map<String, Object> domain;
public final List<Map<String, Object>> clusters;

public Resources(Map<String, Object> domain, List<Map<String, Object>> clusters) {
this.domain = domain;
this.clusters = clusters;
}
public record Resources(Map<String, Object> domain, List<Map<String, Object>> clusters) {
}

/**
Expand Down Expand Up @@ -164,7 +157,7 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
}

restore(PRESERVED_V8, domain);
restore(PRESERVED_AUX, domain, this::validateRestoreLegacyAuxilaryImages);
restore(PRESERVED_AUX, domain, this::validateRestoreLegacyAuxiliaryImages);
removeAddedAdminChannelPortForwardingEnabled(domain);
} else {
restore(PRESERVED_V9, domain);
Expand Down Expand Up @@ -513,13 +506,7 @@ private static Object convertWithMap(Map<String, String> map, Object value) {
}

private Map<String, String> select(Map<String, String> apiVersion9, Map<String, String> apiVersion8) {
switch (targetAPIVersion) {
case API_VERSION_V8:
return apiVersion8;
case API_VERSION_V9:
default:
return apiVersion9;
}
return targetAPIVersion.equals(API_VERSION_V8) ? apiVersion8 : apiVersion9;
}

private static final Map<String, String> serverStartPolicyMap = Map.of(
Expand Down Expand Up @@ -578,7 +565,7 @@ Map<String, Object> getMetadata(Map<String, Object> domain) {
}

@SuppressWarnings("unchecked")
private boolean validateRestoreLegacyAuxilaryImages(Map<String, Object> domain,
private boolean validateRestoreLegacyAuxiliaryImages(Map<String, Object> domain,
Map<String, Object> scope, Map<String, Object> value) {
List<Object> auxiliaryImages = (List<Object>) value.get(AUXILIARY_IMAGES);
if (auxiliaryImages != null) {
Expand Down Expand Up @@ -638,10 +625,10 @@ private void addAuxiliaryImageEnv(List<Object> auxiliaryImages, Map<String, Obje
private String getAuxiliaryImagePaths(List<Object> auxiliaryImages,
List<Object> auxiliaryImageVolumes) {
return Optional.ofNullable(auxiliaryImages).map(
aiList -> createauxiliaryImagePathsEnv(aiList, auxiliaryImageVolumes)).orElse(null);
aiList -> createAuxiliaryImagePathsEnv(aiList, auxiliaryImageVolumes)).orElse(null);
}

private String createauxiliaryImagePathsEnv(List<Object> auxiliaryImages, List<Object> auxiliaryImageVolumes) {
private String createAuxiliaryImagePathsEnv(List<Object> auxiliaryImages, List<Object> auxiliaryImageVolumes) {
StringJoiner auxiliaryImagePaths = new StringJoiner(",","","");
auxiliaryImages.forEach(auxiliaryImage -> auxiliaryImagePaths.add(
getMountPath((Map<String,Object>)auxiliaryImage, auxiliaryImageVolumes)));
Expand Down Expand Up @@ -815,7 +802,7 @@ private void removeAndPreserveConditionsV9(Map<String, Object> status, Map<Strin
return false;
}
return true;
}).collect(Collectors.toList());
}).toList();
if (filteredConditions.isEmpty()) {
status.remove(CONDITIONS);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, 2022, Oracle and/or its affiliates.
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.kubernetes.common.logging;
Expand Down Expand Up @@ -421,10 +421,7 @@ public void setLevel(Level level) {

public boolean isLoggable(Level level) {
int levelValue = this.level.intValue();
if (level.intValue() < levelValue || levelValue == Level.OFF.intValue()) {
return false;
}
return true;
return level.intValue() >= levelValue && levelValue != Level.OFF.intValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) 2019, 2022, Oracle and/or its affiliates.
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.kubernetes.common.logging;

import oracle.kubernetes.common.logging.OncePerMessageLoggingFilter;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down
Loading

0 comments on commit 124ec36

Please sign in to comment.