Move StartOperationAuditEvent to request package
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d3d24a13 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d3d24a13 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d3d24a13 Branch: refs/heads/audit_logging Commit: d3d24a136d36d45f7c630779657c26788fa413f0 Parents: 431e977 Author: Daniel Gergely <[email protected]> Authored: Wed Mar 2 14:02:38 2016 +0100 Committer: Toader, Sebastian <[email protected]> Committed: Thu Mar 24 13:06:49 2016 +0100 ---------------------------------------------------------------------- .../audit/event/StartOperationAuditEvent.java | 115 ------------------ .../event/StartOperationRequestAuditEvent.java | 117 +++++++++++++++++++ .../eventcreator/ComponentEventCreator.java | 4 +- .../eventcreator/ServiceEventCreator.java | 4 +- .../audit/StartOperationAuditEventTest.java | 80 ------------- .../StartOperationRequestAuditEventTest.java | 80 +++++++++++++ 6 files changed, 201 insertions(+), 199 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/d3d24a13/ambari-server/src/main/java/org/apache/ambari/server/audit/event/StartOperationAuditEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/StartOperationAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/StartOperationAuditEvent.java deleted file mode 100644 index 58caf0a..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/StartOperationAuditEvent.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.audit.event; - - -import javax.annotation.concurrent.Immutable; - -/** - * Start operation request was accepted. - */ -@Immutable -public class StartOperationAuditEvent extends AbstractUserAuditEvent { - - public static class StartOperationAuditEventBuilder - extends AbstractUserAuditEventBuilder<StartOperationAuditEvent, StartOperationAuditEventBuilder> { - - private String requestId; - - private String reasonOfFailure; - - private String operation; - - private StartOperationAuditEventBuilder() { - } - - /** - * Appends to the audit event the identifier of the - * operation through whcih the operation progress can be tracked. - * - * @param builder builder for the audit event details. - */ - @Override - protected void buildAuditMessage(StringBuilder builder) { - super.buildAuditMessage(builder); - - builder - .append(", Operation(") - .append(operation) - .append("), RequestId(") - .append(requestId) - .append("), Status(") - .append(reasonOfFailure == null ? "Successfully queued" : "Failed to queue"); - - if (reasonOfFailure != null) { - builder.append("), Reason(") - .append(reasonOfFailure); - } - builder.append(")"); - } - - /** - * {@inheritDoc} - */ - @Override - protected StartOperationAuditEvent newAuditEvent() { - return new StartOperationAuditEvent(this); - } - - /** - * Sets the identifier of the operation through which the operation progress can be tracked. - * - * @param requestId the identifier of the operation through which the operation progress can be tracked. - * @return this builder - */ - public StartOperationAuditEventBuilder withRequestId(String requestId) { - this.requestId = requestId; - return this; - } - - public StartOperationAuditEventBuilder withReasonOfFailure(String reasonOfFailure) { - this.reasonOfFailure = reasonOfFailure; - return this; - } - - public StartOperationAuditEventBuilder withOperation(String operation) { - this.operation = operation; - return this; - } - } - - private StartOperationAuditEvent() { - } - - /** - * {@inheritDoc} - */ - private StartOperationAuditEvent(StartOperationAuditEventBuilder builder) { - super(builder); - } - - /** - * Returns an builder for {@link StartOperationAuditEvent} - * - * @return a builder instance - */ - public static StartOperationAuditEventBuilder builder() { - return new StartOperationAuditEventBuilder(); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/d3d24a13/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/event/StartOperationRequestAuditEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/event/StartOperationRequestAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/event/StartOperationRequestAuditEvent.java new file mode 100644 index 0000000..4f73f75 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/event/StartOperationRequestAuditEvent.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.audit.event.request.event; + + +import javax.annotation.concurrent.Immutable; + +import org.apache.ambari.server.audit.event.AbstractUserAuditEvent; + +/** + * Start operation request was accepted. + */ +@Immutable +public class StartOperationRequestAuditEvent extends AbstractUserAuditEvent { + + public static class StartOperationAuditEventBuilder + extends AbstractUserAuditEventBuilder<StartOperationRequestAuditEvent, StartOperationAuditEventBuilder> { + + private String requestId; + + private String reasonOfFailure; + + private String operation; + + private StartOperationAuditEventBuilder() { + } + + /** + * Appends to the audit event the identifier of the + * operation through whcih the operation progress can be tracked. + * + * @param builder builder for the audit event details. + */ + @Override + protected void buildAuditMessage(StringBuilder builder) { + super.buildAuditMessage(builder); + + builder + .append(", Operation(") + .append(operation) + .append("), RequestId(") + .append(requestId) + .append("), Status(") + .append(reasonOfFailure == null ? "Successfully queued" : "Failed to queue"); + + if (reasonOfFailure != null) { + builder.append("), Reason(") + .append(reasonOfFailure); + } + builder.append(")"); + } + + /** + * {@inheritDoc} + */ + @Override + protected StartOperationRequestAuditEvent newAuditEvent() { + return new StartOperationRequestAuditEvent(this); + } + + /** + * Sets the identifier of the operation through which the operation progress can be tracked. + * + * @param requestId the identifier of the operation through which the operation progress can be tracked. + * @return this builder + */ + public StartOperationAuditEventBuilder withRequestId(String requestId) { + this.requestId = requestId; + return this; + } + + public StartOperationAuditEventBuilder withReasonOfFailure(String reasonOfFailure) { + this.reasonOfFailure = reasonOfFailure; + return this; + } + + public StartOperationAuditEventBuilder withOperation(String operation) { + this.operation = operation; + return this; + } + } + + private StartOperationRequestAuditEvent() { + } + + /** + * {@inheritDoc} + */ + private StartOperationRequestAuditEvent(StartOperationAuditEventBuilder builder) { + super(builder); + } + + /** + * Returns an builder for {@link StartOperationRequestAuditEvent} + * + * @return a builder instance + */ + public static StartOperationAuditEventBuilder builder() { + return new StartOperationAuditEventBuilder(); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/d3d24a13/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ComponentEventCreator.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ComponentEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ComponentEventCreator.java index f9685a5..e0877eb 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ComponentEventCreator.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ComponentEventCreator.java @@ -26,7 +26,7 @@ import org.apache.ambari.server.api.services.Request; import org.apache.ambari.server.api.services.Result; import org.apache.ambari.server.api.services.ResultStatus; import org.apache.ambari.server.audit.event.AuditEvent; -import org.apache.ambari.server.audit.event.StartOperationAuditEvent; +import org.apache.ambari.server.audit.event.request.event.StartOperationRequestAuditEvent; import org.apache.ambari.server.audit.event.request.RequestAuditEventCreator; import org.apache.ambari.server.controller.internal.RequestOperationLevel; import org.apache.ambari.server.controller.spi.Resource; @@ -95,7 +95,7 @@ public class ComponentEventCreator implements RequestAuditEventCreator { requestId = getRequestId(result); } - StartOperationAuditEvent.StartOperationAuditEventBuilder auditEventBuilder = StartOperationAuditEvent.builder() + StartOperationRequestAuditEvent.StartOperationAuditEventBuilder auditEventBuilder = StartOperationRequestAuditEvent.builder() .withOperation(operation) .withUserName(username) .withRemoteIp(request.getRemoteAddress()) http://git-wip-us.apache.org/repos/asf/ambari/blob/d3d24a13/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ServiceEventCreator.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ServiceEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ServiceEventCreator.java index ea08f56..1a5fd3c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ServiceEventCreator.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/eventcreator/ServiceEventCreator.java @@ -26,7 +26,7 @@ import org.apache.ambari.server.api.services.Request; import org.apache.ambari.server.api.services.Result; import org.apache.ambari.server.api.services.ResultStatus; import org.apache.ambari.server.audit.event.AuditEvent; -import org.apache.ambari.server.audit.event.StartOperationAuditEvent; +import org.apache.ambari.server.audit.event.request.event.StartOperationRequestAuditEvent; import org.apache.ambari.server.audit.event.request.RequestAuditEventCreator; import org.apache.ambari.server.audit.event.request.event.DeleteServiceRequestAuditEvent; import org.apache.ambari.server.controller.internal.RequestOperationLevel; @@ -108,7 +108,7 @@ public class ServiceEventCreator implements RequestAuditEventCreator { requestId = getRequestId(result); } - StartOperationAuditEvent.StartOperationAuditEventBuilder auditEventBuilder = StartOperationAuditEvent.builder() + StartOperationRequestAuditEvent.StartOperationAuditEventBuilder auditEventBuilder = StartOperationRequestAuditEvent.builder() .withOperation(operation) .withUserName(username) .withRemoteIp(request.getRemoteAddress()) http://git-wip-us.apache.org/repos/asf/ambari/blob/d3d24a13/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationAuditEventTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationAuditEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationAuditEventTest.java deleted file mode 100644 index 360d494..0000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationAuditEventTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ambari.server.audit; - -import org.apache.ambari.server.audit.event.LoginAuditEvent; -import org.apache.ambari.server.audit.event.StartOperationAuditEvent; -import org.joda.time.DateTime; -import org.junit.Test; - -import nl.jqno.equalsverifier.EqualsVerifier; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -public class StartOperationAuditEventTest { - - @Test - public void testAuditMessage() throws Exception { - // Given - String testUserName = "USER1"; - String testRemoteIp = "127.0.0.1"; - String testRequestDetails = "{ \"key\": \"value\"}"; - Long testRequestId = 100L; - - StartOperationAuditEvent evnt = StartOperationAuditEvent.builder() - .withTimestamp(DateTime.now()) - .withRemoteIp(testRemoteIp) - .withUserName(testUserName) - .withOperation(testRequestDetails) - .withRequestId(testRequestId.toString()) - .build(); - - // When - String actualAuditMessage = evnt.getAuditMessage(); - - // Then - String expectedAuditMessage = String.format("User(%s), RemoteIp(%s), Operation(%s), RequestId(%d), Status(Successfully queued)", testUserName, testRemoteIp, testRequestDetails, testRequestId); - - assertThat(actualAuditMessage, equalTo(expectedAuditMessage)); - - } - - @Test - public void testTimestamp() throws Exception { - // Given - DateTime testTimestamp = DateTime.now(); - StartOperationAuditEvent evnt = StartOperationAuditEvent.builder() - .withTimestamp(testTimestamp) - .build(); - - // When - DateTime actualTimestamp = evnt.getTimestamp(); - - // Then - assertThat(actualTimestamp, equalTo(testTimestamp)); - - } - - - @Test - public void testEquals() throws Exception { - EqualsVerifier.forClass(LoginAuditEvent.class) - .verify(); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/d3d24a13/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationRequestAuditEventTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationRequestAuditEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationRequestAuditEventTest.java new file mode 100644 index 0000000..0aabd4b --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/StartOperationRequestAuditEventTest.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ambari.server.audit; + +import org.apache.ambari.server.audit.event.LoginAuditEvent; +import org.apache.ambari.server.audit.event.request.event.StartOperationRequestAuditEvent; +import org.joda.time.DateTime; +import org.junit.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +public class StartOperationRequestAuditEventTest { + + @Test + public void testAuditMessage() throws Exception { + // Given + String testUserName = "USER1"; + String testRemoteIp = "127.0.0.1"; + String testRequestDetails = "{ \"key\": \"value\"}"; + Long testRequestId = 100L; + + StartOperationRequestAuditEvent evnt = StartOperationRequestAuditEvent.builder() + .withTimestamp(DateTime.now()) + .withRemoteIp(testRemoteIp) + .withUserName(testUserName) + .withOperation(testRequestDetails) + .withRequestId(testRequestId.toString()) + .build(); + + // When + String actualAuditMessage = evnt.getAuditMessage(); + + // Then + String expectedAuditMessage = String.format("User(%s), RemoteIp(%s), Operation(%s), RequestId(%d), Status(Successfully queued)", testUserName, testRemoteIp, testRequestDetails, testRequestId); + + assertThat(actualAuditMessage, equalTo(expectedAuditMessage)); + + } + + @Test + public void testTimestamp() throws Exception { + // Given + DateTime testTimestamp = DateTime.now(); + StartOperationRequestAuditEvent evnt = StartOperationRequestAuditEvent.builder() + .withTimestamp(testTimestamp) + .build(); + + // When + DateTime actualTimestamp = evnt.getTimestamp(); + + // Then + assertThat(actualTimestamp, equalTo(testTimestamp)); + + } + + + @Test + public void testEquals() throws Exception { + EqualsVerifier.forClass(LoginAuditEvent.class) + .verify(); + } +}
