Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chained container proxies configuration refactor #8658

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/

package com.redhat.rhn.common;

import static com.redhat.rhn.common.ExceptionMessage.NOT_INSTANTIABLE;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Supplier;

public class ErrorReportingStrategies {

private ErrorReportingStrategies() {
throw new UnsupportedOperationException(NOT_INSTANTIABLE);
}

private static final Map<Object, Logger> OBJ_LOGGER = Collections.synchronizedMap(new WeakHashMap<>());

/**
* Raise and log an exception
* @param obj Object to log
* @param message Message to log
* @return Supplier of RhnRuntimeException that logs the message and throw the exception
*/
public static Supplier<RhnRuntimeException> raiseAndLog(Object obj, String message) {
Logger logger = OBJ_LOGGER.computeIfAbsent(obj, key -> LogManager.getLogger(obj.getClass().getName()));
return () -> {
logger.error(message);
return new RhnRuntimeException(message);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.SystemOverview;
import com.redhat.rhn.frontend.xmlrpc.BaseHandler;
import com.redhat.rhn.frontend.xmlrpc.IOFaultException;
import com.redhat.rhn.frontend.xmlrpc.InvalidParameterException;
import com.redhat.rhn.frontend.xmlrpc.InvalidProxyVersionException;
import com.redhat.rhn.frontend.xmlrpc.MethodInvalidParamException;
Expand All @@ -34,7 +33,6 @@
import com.redhat.rhn.frontend.xmlrpc.ProxyNotActivatedException;
import com.redhat.rhn.frontend.xmlrpc.ProxySystemIsSatelliteException;
import com.redhat.rhn.frontend.xmlrpc.SSLCertFaultException;
import com.redhat.rhn.frontend.xmlrpc.SystemIdInstantiationException;
import com.redhat.rhn.frontend.xmlrpc.system.XmlRpcSystemHelper;
import com.redhat.rhn.manager.entitlement.EntitlementManager;
import com.redhat.rhn.manager.system.SystemManager;
Expand All @@ -48,7 +46,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -297,14 +294,6 @@ public byte[] containerConfig(User loggedInUser, String proxyName, Integer proxy
maxCache.longValue(), email, rootCA, intermediateCAs, proxyCrtKey, null, null, null,
new SSLCertManager());
}
catch (InstantiationException e) {
LOG.error("Failed to generate proxy system id", e);
throw new SystemIdInstantiationException();
}
catch (IOException e) {
LOG.error("Failed to generate container config", e);
throw new IOFaultException(e);
}
catch (SSLCertGenerationException e) {
LOG.error("Failed to generate SSL certificate", e);
throw new SSLCertFaultException(e.getMessage());
Expand Down Expand Up @@ -369,14 +358,6 @@ public byte[] containerConfig(User loggedInUser, String proxyName, Integer proxy
maxCache.longValue(), email, null, List.of(), null, caCrtKey, caPassword, certData,
new SSLCertManager());
}
catch (InstantiationException e) {
LOG.error("Failed to generate proxy system id", e);
throw new SystemIdInstantiationException();
}
catch (IOException e) {
LOG.error("Failed to generate container config", e);
throw new IOFaultException(e);
}
catch (SSLCertGenerationException e) {
LOG.error("Failed to generate SSL certificate", e);
throw new SSLCertFaultException(e.getMessage());
Expand Down
Loading
Loading