Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@FrankGasparovic
Copy link

No description provided.

auditPayload.put("httpMethod", auditEvent.getMethod());
auditPayload.put("requestBody", auditEvent.getRequestBody());
auditPayload.put("responseBody", auditEvent.getResponseBody());

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we create a json string out of auditPayload and then store it in payload field.

Copy link
Contributor

@anubhavi25 anubhavi25 left a comment

Choose a reason for hiding this comment

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

As discussed, I checked in the CheckStyle fixes to service/src/test/java/com/ge/predix/acs/audit/PredixEventMapperTest.java so please pull those changes.


public class PredixEventMapper {

public AuditEventV2 map(final com.ge.predix.audit.AuditEvent auditEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to specify the full package name since now there's no name clash between AuditEvent and AuditEventV2

public class PredixEventMapper {

public AuditEventV2 map(final com.ge.predix.audit.AuditEvent auditEvent) {
Map<String, String> auditPayload = new HashMap<String, String>();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just use the diamond operator <> since you already gave the type specification via the Map declaration: Map<String, String> auditPayload = new HashMap<>();

Copy link
Author

Choose a reason for hiding this comment

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

Removed


}

private boolean isSuccessful(final com.ge.predix.audit.AuditEvent auditEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment re. not needing the full package name

Copy link
Author

Choose a reason for hiding this comment

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

Removed

AuditEventV2Builder auditEventBuilder = AuditEventV2.builder().timestamp(auditEvent.getTime().toEpochMilli())
.correlationId(auditEvent.getCorrelationId()).tenantUuid(auditEvent.getZoneId())
.publisherType(PublisherType.APP_SERVICE).categoryType(CategoryType.API_CALLS)
.payload(auditPayload.toString());
Copy link
Contributor

@anubhavi25 anubhavi25 Feb 22, 2017

Choose a reason for hiding this comment

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

auditPayload.toString() will invoke AbstractMap#toString() which looks like JSON but isn't. Echoing @anurag-gujral, shouldn't we be serializing this as JSON instead?

Copy link
Author

Choose a reason for hiding this comment

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

Am now serializing

@Autowired
private AuditClient auditClient;

@Autowired
Copy link
Contributor

Choose a reason for hiding this comment

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

This coincidentally works since PredixEventProcessor and PredixEventMapper are part of the same package, but it might break if trying to wire an instance of PredixEventMapper elsewhere. Perhaps add an @Component annotation to the PredixEventMapper class above?

Copy link
Author

Choose a reason for hiding this comment

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

Added

Copy link
Contributor

Choose a reason for hiding this comment

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

This has not been addressed, frank can you please comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

@anurag-gujral, @FrankGasparovic has addressed this above.

CategoryType.API_CALLS, EventType.FAILURE_API_REQUEST, Classifier.FAILURE },
{ "request body", "PUT", 200, "response body", "9101112", "13141516", PublisherType.APP_SERVICE,
CategoryType.API_CALLS, EventType.SUCCESS_API_REQUEST, Classifier.SUCCESS } };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably add at least one test for auditing input validation failures: { ... , PublisherType.APP_SERVICE, CategoryType.MALICIOUS, EventType.INVALID_INPUTS, Classifier.FAILURE }

If it's outside the scope of the current release, we should at least create a story to track this.

Copy link
Author

Choose a reason for hiding this comment

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

Added story for this in audit feature

Copy link
Contributor

Choose a reason for hiding this comment

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

The story for CategoryType.MALICIOUS /input validation has been added to the backlog.

service/pom.xml Outdated
</dependencyManagement>
<dependencies>

<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't necessary since the audit-sdk dependencies have already been added to the POMs. All that's necessary is to change the version in the <audit-sdk.version>0.0.x-SNAPSHOT</audit-sdk.version> line in the top-level POM.

That said, we should add something like the following to the public Maven profile in this POM to exclude compilation of all src and test classes in the com.ge.predix.acs.audit package:

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.3</version>
                        <configuration>
                            <excludes>
                                <exclude>com/ge/predix/acs/audit/*</exclude>
                            </excludes>
                            <testExcludes>
                                <testExclude>com/ge/predix/acs/audit/*</testExclude>
                            </testExcludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

import com.ge.predix.audit.sdk.AuditClient;
import com.ge.predix.audit.sdk.exception.AuditException;
import com.ge.predix.audit.sdk.message.AuditEventV2;
import com.ge.predix.eventhub.EventHubClientException;
Copy link
Contributor

@anubhavi25 anubhavi25 Feb 22, 2017

Choose a reason for hiding this comment

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

To allow this import to be resolved, we probably want to explicitly add the EventHub SDK dependency to the predix Maven profile of acs/service/pom.xml:

                <dependency>
                    <groupId>com.ge.predix.eventhub</groupId>
                    <artifactId>predix-event-hub-sdk</artifactId>
                    <version>${predix-event-hub-sdk.version}</version>
                </dependency>

Copy link
Author

Choose a reason for hiding this comment

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

added


@BeforeMethod
public void setup() throws AuditException, EventHubClientException {
this.eventProcessor = new PredixEventProcessor();
Copy link
Contributor

Choose a reason for hiding this comment

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

Contrary to what we thought, this line to instantiate this.eventProcessor doesn't seem necessary (runs without a NullPointerException for me)

Copy link
Author

Choose a reason for hiding this comment

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

Removed


@Test
public void testPredixEventProcess() throws AuditException, EventHubClientException {
AuditEventV2 mockPredixEvent = Mockito.mock(AuditEventV2.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly better since it passes a mock object to process(...) instead of null:

    @Test
    public void testPredixEventProcess() throws AuditException, EventHubClientException {
        AuditEvent mockAuditEvent = Mockito.mock(AuditEvent.class);
        AuditEventV2 mockPredixEvent = Mockito.mock(AuditEventV2.class);
        Mockito.when(mockedMapper.map(mockAuditEvent)).thenReturn(mockPredixEvent);

        Assert.assertTrue(this.eventProcessor.process(mockAuditEvent));
        Mockito.verify(mockedClient).audit(mockPredixEvent);
    }

Copy link
Author

Choose a reason for hiding this comment

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

Added

@anubhavi25 anubhavi25 changed the title US65644: Creating Audit Event Mapping for ACS US65644: Map ACS-specific audit events to Predix-specific ones Feb 23, 2017

public AuditEventV2 map(final AuditEvent auditEvent) {
Map<String, String> auditPayload = new HashMap<>();
auditPayload.put("httpMethod", auditEvent.getMethod());
Copy link
Contributor

Choose a reason for hiding this comment

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

May next time when we commit we can make hardcoded string to private final String members

Copy link
Author

Choose a reason for hiding this comment

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

Only used in one place at the moment.

String payload = "";
try {
payload = this.objectMapper.writeValueAsString(auditPayload);
} catch (JsonProcessingException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not look correct, the map function should throw an exception instead of just logging.

Copy link
Author

Choose a reason for hiding this comment

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

We are only constructing well formed JSON in this map method with potentially "garbage" as values in the JSON. I don't see a reason that we should throw this exception.

Copy link
Author

Choose a reason for hiding this comment

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

Also the values in the auditPayload cannot be null, so we shouldn't have problems.

@Override
public boolean process(final AuditEvent auditEvent) {
AuditEventV2 predixEvent = eventMapper.map(auditEvent);
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need proper exception handling rather than catching the exception and returning boolean

Copy link
Author

@FrankGasparovic FrankGasparovic Feb 23, 2017

Choose a reason for hiding this comment

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

Boolean is required because of the way we created the tests for the AuditEventProcessor. Also we shouldn't add the throws at the interface level because different implementations of AuditEventProcessor may not use the Predix-Audit SDK.

@anubhavi25 anubhavi25 merged commit 020806b into develop Feb 23, 2017
@anubhavi25 anubhavi25 deleted the US65644 branch February 23, 2017 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants