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

HDDS-11194. OM missing audit log for upgrade prepare, cancel and finalize #6958

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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
Expand Up @@ -36,20 +36,36 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
import org.apache.hadoop.ozone.audit.AuditEventStatus;
import org.apache.hadoop.ozone.audit.AuditLogTestUtils;
import org.apache.hadoop.ozone.audit.OMAction;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import org.apache.hadoop.ozone.om.ratis.OzoneManagerStateMachine;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages;

import org.apache.ratis.util.LifeCycle;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Tests for OM upgrade finalization.
* TODO: can be merged into class with other OM tests with per-method cluster
*/
class TestOMUpgradeFinalization {
static {
AuditLogTestUtils.enableAuditLog();
}

@BeforeEach
public void setup() throws Exception {
AuditLogTestUtils.truncateAuditLogFile();
}
@AfterAll
public static void shutdown() {
AuditLogTestUtils.deleteAuditLogFile();
}
@Test
void testOMUpgradeFinalizationWithOneOMDown() throws Exception {
OzoneConfiguration conf = new OzoneConfiguration();
Expand All @@ -70,11 +86,14 @@ void testOMUpgradeFinalizationWithOneOMDown() throws Exception {
// OMs.
long prepareIndex = omClient.prepareOzoneManager(120L, 5L);
assertClusterPrepared(prepareIndex, runningOms);
AuditLogTestUtils.verifyAuditLog(OMAction.UPGRADE_PREPARE, AuditEventStatus.SUCCESS);

omClient.cancelOzoneManagerPrepare();
AuditLogTestUtils.verifyAuditLog(OMAction.UPGRADE_CANCEL, AuditEventStatus.SUCCESS);
StatusAndMessages response =
omClient.finalizeUpgrade("finalize-test");
System.out.println("Finalization Messages : " + response.msgs());
AuditLogTestUtils.verifyAuditLog(OMAction.UPGRADE_FINALIZE, AuditEventStatus.SUCCESS);

waitForFinalization(omClient);
cluster.restartOzoneManager(downedOM, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public enum OMAction implements AuditAction {
SNAPSHOT_INFO,
SET_TIMES,

ABORT_EXPIRED_MULTIPART_UPLOAD;
ABORT_EXPIRED_MULTIPART_UPLOAD,
UPGRADE_PREPARE,
UPGRADE_CANCEL,
UPGRADE_FINALIZE;

@Override
public String getAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.apache.hadoop.ozone.om.request.upgrade;

import java.util.HashMap;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.exceptions.OMException;
Expand Down Expand Up @@ -54,10 +58,13 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
LOG.info("OM {} Received cancel prepare request with log {}", ozoneManager.getOMNodeId(), termIndex);

OMRequest omRequest = getOmRequest();
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = omRequest.getUserInfo();
OMResponse.Builder responseBuilder =
OmResponseUtil.getOMResponseBuilder(omRequest);
responseBuilder.setCmdType(Type.CancelPrepare);
OMClientResponse response = null;
Exception exception = null;

try {
UserGroupInformation ugi = createUGIForApi();
Expand All @@ -82,12 +89,15 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
LOG.info("OM {} prepare state cancelled at log {}. Returning response {}",
ozoneManager.getOMNodeId(), termIndex, omResponse);
} catch (IOException e) {
exception = e;
LOG.error("Cancel Prepare Request apply failed in {}. ",
ozoneManager.getOMNodeId(), e);
response = new OMPrepareResponse(
createErrorOMResponse(responseBuilder, e));
}

auditLog(auditLogger, buildAuditMessage(OMAction.UPGRADE_CANCEL,
new HashMap<>(), exception, userInfo));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add OMNodeId and termIndex in auditMap as an additional info for audit message ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TermIndex will be handled as part of "HDDS-10658. Add Object ID and Update ID to OM audit log messages" when this is merged.
OMNodeId is not required as audit-log is per node itself. There is no need for same.

return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
import static org.apache.hadoop.ozone.OzoneConsts.LAYOUT_VERSION_KEY;
import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type.FinalizeUpgrade;

import java.util.HashMap;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos
.UpgradeFinalizationStatus;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
Expand Down Expand Up @@ -58,10 +62,13 @@ public OMFinalizeUpgradeRequest(OMRequest omRequest) {
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIndex termIndex) {
LOG.trace("Request: {}", getOmRequest());
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
OMResponse.Builder responseBuilder =
OmResponseUtil.getOMResponseBuilder(getOmRequest());
responseBuilder.setCmdType(FinalizeUpgrade);
OMClientResponse response = null;
Exception exception = null;

try {
if (ozoneManager.getAclsEnabled()) {
Expand Down Expand Up @@ -103,10 +110,13 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
ozoneManager.getVersionManager().getMetadataLayoutVersion());
LOG.trace("Returning response: {}", response);
} catch (IOException e) {
exception = e;
response = new OMFinalizeUpgradeResponse(
createErrorOMResponse(responseBuilder, e), -1);
}

auditLog(auditLogger, buildAuditMessage(OMAction.UPGRADE_FINALIZE,
new HashMap<>(), exception, userInfo));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add termIndex in auditMap as an additional info for audit message ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TermIndex will be handled as part of "HDDS-10658. Add Object ID and Update ID to OM audit log messages" when this is merged.

return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.hadoop.ozone.om.request.upgrade;

import java.util.HashMap;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.exceptions.OMException;
Expand Down Expand Up @@ -69,12 +72,15 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
LOG.info("OM {} Received prepare request with log {}", ozoneManager.getOMNodeId(), termIndex);

OMRequest omRequest = getOmRequest();
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = omRequest.getUserInfo();
OzoneManagerProtocolProtos.PrepareRequestArgs args =
omRequest.getPrepareRequest().getArgs();
OMResponse.Builder responseBuilder =
OmResponseUtil.getOMResponseBuilder(omRequest);
responseBuilder.setCmdType(Type.Prepare);
OMClientResponse response = null;
Exception exception = null;

// Allow double buffer this many seconds to flush all transactions before
// returning an error to the caller.
Expand Down Expand Up @@ -123,13 +129,15 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
"log index {}", ozoneManager.getOMNodeId(), transactionLogIndex,
omResponse, omResponse.getTxnID());
} catch (OMException e) {
exception = e;
LOG.error("Prepare Request Apply failed in {}. ",
ozoneManager.getOMNodeId(), e);
response = new OMPrepareResponse(
createErrorOMResponse(responseBuilder, e));
} catch (InterruptedException | IOException e) {
// Set error code so that prepare failure does not cause the OM to
// terminate.
exception = e;
LOG.error("Prepare Request Apply failed in {}. ",
ozoneManager.getOMNodeId(), e);
response = new OMPrepareResponse(
Expand All @@ -149,6 +157,8 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
}
}

auditLog(auditLogger, buildAuditMessage(OMAction.UPGRADE_PREPARE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add transactionLogIndex and OMNodeId in auditMap as an additional info for audit message ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TermIndex will be handled as part of "HDDS-10658. Add Object ID and Update ID to OM audit log messages" when this is merged implicitly.
OMNodeId is not required as audit-log is per node itself. There is no need for same.

new HashMap<>(), exception, userInfo));
return response;
}

Expand Down