-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a notification service with a SNS implementation (#17)
- Loading branch information
Showing
37 changed files
with
2,197 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed 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:https://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. | ||
* | ||
*/ | ||
|
||
/** | ||
* Data transfer objects related to notification events. | ||
* | ||
* @author tgianos | ||
* @since 0.1.47 | ||
*/ | ||
package com.netflix.metacat.common.dto.notifications; |
70 changes: 70 additions & 0 deletions
70
...cat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/SNSMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed 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:https://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 com.netflix.metacat.common.dto.notifications.sns; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.netflix.metacat.common.dto.BaseDto; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Base SNS notification DTO with shared fields. | ||
* | ||
* @param <P> The type of payload this notification has | ||
* @author tgianos | ||
* @since 0.1.47 | ||
*/ | ||
@Getter | ||
@ToString | ||
public class SNSMessage<P> extends BaseDto { | ||
|
||
private final String id; | ||
private final long timestamp; | ||
private final String requestId; | ||
private final String name; | ||
private final SNSMessageType type; | ||
private final P payload; | ||
|
||
/** | ||
* Create a new SNSMessage. | ||
* | ||
* @param id The unique id of the message | ||
* @param timestamp The number of milliseconds since epoch that this message occurred | ||
* @param requestId The id of the API request that generated this and possibly other messages. Used for grouping | ||
* @param type The type of notification | ||
* @param name The qualified name of the resource that this notification is being generated for | ||
* @param payload The payload of the notification | ||
*/ | ||
@JsonCreator | ||
public SNSMessage( | ||
@JsonProperty("id") final String id, | ||
@JsonProperty("timestamp") final long timestamp, | ||
@JsonProperty("requestId") final String requestId, | ||
@JsonProperty("type") final SNSMessageType type, | ||
@JsonProperty("name") final String name, | ||
@JsonProperty("payload") final P payload | ||
) { | ||
this.id = id; | ||
this.timestamp = timestamp; | ||
this.requestId = requestId; | ||
this.type = type; | ||
this.name = name; | ||
this.payload = payload; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...mon/src/main/java/com/netflix/metacat/common/dto/notifications/sns/SNSMessageFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed 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:https://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 com.netflix.metacat.common.dto.notifications.sns; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.metacat.common.dto.notifications.sns.messages.AddPartitionMessage; | ||
import com.netflix.metacat.common.dto.notifications.sns.messages.CreateTableMessage; | ||
import com.netflix.metacat.common.dto.notifications.sns.messages.DeletePartitionMessage; | ||
import com.netflix.metacat.common.dto.notifications.sns.messages.DeleteTableMessage; | ||
import com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTableMessage; | ||
import com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Create SNSMessage object based on the JSON passed in. | ||
* | ||
* @author tgianos | ||
* @since 0.1.47 | ||
*/ | ||
public class SNSMessageFactory { | ||
|
||
private static final String TYPE_FIELD = "type"; | ||
private final ObjectMapper mapper; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param mapper The object mapper to use for deserialization | ||
*/ | ||
public SNSMessageFactory(final ObjectMapper mapper) { | ||
this.mapper = mapper; | ||
} | ||
|
||
/** | ||
* Convert a JSON String into a message if possible. | ||
* | ||
* @param json The body of the message to convert back to the original message object from JSON string | ||
* @return The message bound back into a POJO | ||
* @throws IOException When the input isn't valid JSON | ||
*/ | ||
public SNSMessage<?> getMessage(final String json) throws IOException { | ||
final JsonNode object = this.mapper.readTree(json); | ||
if (object.has(TYPE_FIELD)) { | ||
final SNSMessageType messageType = SNSMessageType.valueOf(object.get(TYPE_FIELD).asText()); | ||
switch (messageType) { | ||
case TABLE_CREATE: | ||
return this.mapper.readValue(json, CreateTableMessage.class); | ||
case TABLE_DELETE: | ||
return this.mapper.readValue(json, DeleteTableMessage.class); | ||
case TABLE_UPDATE: | ||
return this.mapper.readValue(json, UpdateTableMessage.class); | ||
case TABLE_PARTITIONS_UPDATE: | ||
return this.mapper.readValue(json, UpdateTablePartitionsMessage.class); | ||
case PARTITION_ADD: | ||
return this.mapper.readValue(json, AddPartitionMessage.class); | ||
case PARTITION_DELETE: | ||
return this.mapper.readValue(json, DeletePartitionMessage.class); | ||
default: | ||
throw new UnsupportedOperationException("Unknown type " + messageType); | ||
} | ||
} else { | ||
// won't know how to bind | ||
throw new IOException("Invalid content. No field type field found"); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/SNSMessageType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed 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:https://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 com.netflix.metacat.common.dto.notifications.sns; | ||
|
||
/** | ||
* Enumeration of the various types of SNS events there can be. | ||
* | ||
* @author tgianos | ||
* @since 0.1.47 | ||
*/ | ||
public enum SNSMessageType { | ||
/** | ||
* When a table is created. | ||
*/ | ||
TABLE_CREATE, | ||
|
||
/** | ||
* When a table is deleted. | ||
*/ | ||
TABLE_DELETE, | ||
|
||
/** | ||
* When the metadata about a table is updated somehow. | ||
*/ | ||
TABLE_UPDATE, | ||
|
||
/** | ||
* When the partitions for a table are either created or deleted. | ||
*/ | ||
TABLE_PARTITIONS_UPDATE, | ||
|
||
/** | ||
* When a partition is added. | ||
*/ | ||
PARTITION_ADD, | ||
|
||
/** | ||
* When a partition is deleted. | ||
*/ | ||
PARTITION_DELETE | ||
} |
Oops, something went wrong.