mneethiraj commented on code in PR #307: URL: https://github.com/apache/atlas/pull/307#discussion_r1996296271
########## intg/src/main/java/org/apache/atlas/AtlasErrorCode.java: ########## @@ -224,7 +224,7 @@ public enum AtlasErrorCode { GLOSSARY_IMPORT_FAILED(409, "ATLAS-409-00-011", "Glossary import failed"), METRICSSTAT_ALREADY_EXISTS(409, "ATLAS-409-00-012", "Metric Statistics already collected at {0}"), PENDING_TASKS_ALREADY_IN_PROGRESS(409, "ATLAS-409-00-013", "There are already {0} pending tasks in queue"), - IMPORT_ALREADY_IN_PROGRESS(409, "ATLAS-409-00-016", "Given import request {0} is already in progress or completed"), + ABORT_IMPORT(409, "ATLAS-409-00-016", "Import id={0} is currently in state {1}, cannot be aborted"), Review Comment: `ABORT_IMPORT` => `IMPORT_ABORT_NOT_ALLOWED` ########## intg/src/main/java/org/apache/atlas/model/notification/ImportNotification.java: ########## @@ -0,0 +1,159 @@ +/** + * 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.atlas.model.notification; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; +import org.apache.atlas.model.typedef.AtlasTypesDef; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import java.io.Serializable; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * Class representing atlas import notification, extending HookNotification. + */ +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude +@JsonIgnoreProperties(ignoreUnknown = true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class ImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + public ImportNotification() { + } + + public ImportNotification(HookNotificationType type, String user) { + super(type, user); + } + + @Override Review Comment: `String toString()` method can be removed from here, as it is identical to the implementation in `HookNotification`. ########## intg/src/main/java/org/apache/atlas/model/impexp/AtlasAsyncImportRequest.java: ########## @@ -0,0 +1,383 @@ +/** + * 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.atlas.model.impexp; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.apache.atlas.model.AtlasBaseModelObject; +import org.apache.atlas.utils.AtlasEntityUtil; + +import java.io.Serializable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.TimeZone; +import java.util.concurrent.ConcurrentHashMap; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class AtlasAsyncImportRequest extends AtlasBaseModelObject implements Serializable { + private static final long serialVersionUID = 1L; + public static final String ASYNC_IMPORT_TYPE_NAME = "__AtlasAsyncImportRequest"; + public static final String ASYNC_IMPORT_TOPIC_PREFIX = "ATLAS_IMPORT_"; + public static final String REQUEST_ID_PREFIX_PROPERTY = "async_import_"; + + public enum ImportStatus { + STAGING("STAGING"), + WAITING("WAITING"), + PROCESSING("PROCESSING"), + SUCCESSFUL("SUCCESSFUL"), + PARTIAL_SUCCESS("PARTIAL_SUCCESS"), + ABORTED("ABORTED"), + FAILED("FAILED"); + + private final String status; + + ImportStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + @Override + public String toString() { + return status; + } + } + + @JsonIgnore + private String requestId; + @JsonIgnore + private int skipTo; + + private String importId; + private ImportStatus status; + private ImportDetails importDetails = new ImportDetails(); + private long receivedAt; + private long stagedAt; + private long startedProcessingAt; + private long completedAt; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private AtlasImportResult atlasImportResult; + + public AtlasAsyncImportRequest() {} + + public AtlasAsyncImportRequest(String guid) { + setGuid(guid); + } + + public AtlasAsyncImportRequest(AtlasImportResult result) { + this.atlasImportResult = result; + this.status = ImportStatus.STAGING; + this.skipTo = 0; + this.receivedAt = 0L; + this.stagedAt = 0L; + this.startedProcessingAt = 0L; + this.completedAt = 0L; + this.importDetails = new ImportDetails(); + setGuid(getGuid()); + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getImportId() { + return importId; + } + + public void setImportId(String importId) { + this.importId = importId; + setRequestId(REQUEST_ID_PREFIX_PROPERTY + importId + "@" + AtlasEntityUtil.getMetadataNamespace()); + } + + public ImportStatus getStatus() { + return status; + } + + public void setStatus(ImportStatus status) { + this.status = status; + } + + public ImportDetails getImportDetails() { + return importDetails; + } + + public void setImportDetails(ImportDetails importDetails) { + this.importDetails = importDetails; + } + + @JsonIgnore + public String getTopicName() { + return ASYNC_IMPORT_TOPIC_PREFIX + importId; + } + + public int getSkipTo() { + return skipTo; + } + + public void setSkipTo(int skipTo) { + this.skipTo = skipTo; + } + + public AtlasImportResult getAtlasImportResult() { + return atlasImportResult; + } + + public void setAtlasImportResult(AtlasImportResult atlasImportResult) { + this.atlasImportResult = atlasImportResult; + } + + public long getReceivedAt() { + return receivedAt; + } + + public void setReceivedAt(long receivedAt) { + this.receivedAt = receivedAt; + } + + public long getStagedAt() { + return stagedAt; + } + + public void setStagedAt(long stagedAt) { + this.stagedAt = stagedAt; + } + + public long getStartedProcessingAt() { + return startedProcessingAt; + } + + public void setStartedProcessingAt(long startedProcessingAt) { + this.startedProcessingAt = startedProcessingAt; + } + + public long getCompletedAt() { + return completedAt; + } + + public void setCompletedAt(long completedAt) { + this.completedAt = completedAt; + } + + @JsonIgnore + public Map<String, Object> getImportMinInfo() { + Map<String, Object> minInfoResponse = new HashMap<>(); + + String importId = this.getImportId(); + long timestamp = this.receivedAt; + String isoDate = toIsoDate(new Date(timestamp)); + + minInfoResponse.put("importId", importId); + minInfoResponse.put("status", status); + minInfoResponse.put("importRequestReceivedAt", isoDate); + minInfoResponse.put("importRequestReceivedBy", atlasImportResult.getUserName()); + + return minInfoResponse; + } + + private String toIsoDate(Date value) { + final TimeZone tz = TimeZone.getTimeZone("UTC"); + final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + df.setTimeZone(tz); + return df.format(value); + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof AtlasAsyncImportRequest)) { + return false; + } + if (!super.equals(o)) { + return false; + } + AtlasAsyncImportRequest that = (AtlasAsyncImportRequest) o; + return Objects.equals(atlasImportResult, that.atlasImportResult) && + Objects.equals(importId, that.importId) && + Objects.equals(status, that.status) && + Objects.equals(importDetails, that.importDetails) && + Objects.equals(requestId, that.requestId) && + Objects.equals(receivedAt, that.receivedAt) && + Objects.equals(stagedAt, that.stagedAt) && + Objects.equals(startedProcessingAt, that.startedProcessingAt) && + Objects.equals(completedAt, that.completedAt); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), requestId, atlasImportResult, + importId, status, importDetails, receivedAt, stagedAt, startedProcessingAt, completedAt); + } + + @Override + protected StringBuilder toString(StringBuilder sb) { + sb.append(", atlasImportResult="); + if (atlasImportResult == null) { + sb.append("null"); + } else { + sb.append(atlasImportResult); + } + sb.append(", requestId=").append(requestId); + sb.append(", importId=").append(importId); + sb.append(", status=").append(status); + sb.append(", receivedAt=").append(receivedAt); + sb.append(", stagedAt=").append(stagedAt); + sb.append(", startedProcessingAt=").append(startedProcessingAt); + sb.append(", completedAt=").append(completedAt); + sb.append(", importDetails=").append(importDetails); + + return sb; + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ImportDetails { Review Comment: - add `implements Serializable` - `failures` is marked as `final`. How does this work drring deserialization? - `failures` is initialized with `ConcurrentHashMap`. Is this necessary? Json deserializer might assign a Hashmap instance. ########## intg/src/main/java/org/apache/atlas/model/impexp/AtlasAsyncImportRequest.java: ########## @@ -0,0 +1,383 @@ +/** + * 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.atlas.model.impexp; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.apache.atlas.model.AtlasBaseModelObject; +import org.apache.atlas.utils.AtlasEntityUtil; + +import java.io.Serializable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.TimeZone; +import java.util.concurrent.ConcurrentHashMap; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class AtlasAsyncImportRequest extends AtlasBaseModelObject implements Serializable { + private static final long serialVersionUID = 1L; + public static final String ASYNC_IMPORT_TYPE_NAME = "__AtlasAsyncImportRequest"; + public static final String ASYNC_IMPORT_TOPIC_PREFIX = "ATLAS_IMPORT_"; + public static final String REQUEST_ID_PREFIX_PROPERTY = "async_import_"; + + public enum ImportStatus { + STAGING("STAGING"), + WAITING("WAITING"), + PROCESSING("PROCESSING"), + SUCCESSFUL("SUCCESSFUL"), + PARTIAL_SUCCESS("PARTIAL_SUCCESS"), + ABORTED("ABORTED"), + FAILED("FAILED"); + + private final String status; + + ImportStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + @Override + public String toString() { + return status; + } + } + + @JsonIgnore + private String requestId; + @JsonIgnore + private int skipTo; + + private String importId; + private ImportStatus status; + private ImportDetails importDetails = new ImportDetails(); + private long receivedAt; + private long stagedAt; + private long startedProcessingAt; + private long completedAt; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private AtlasImportResult atlasImportResult; Review Comment: `atlasImportResult` => `importResult` ########## intg/src/main/java/org/apache/atlas/model/impexp/AtlasAsyncImportRequest.java: ########## @@ -0,0 +1,383 @@ +/** + * 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.atlas.model.impexp; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.apache.atlas.model.AtlasBaseModelObject; +import org.apache.atlas.utils.AtlasEntityUtil; + +import java.io.Serializable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.TimeZone; +import java.util.concurrent.ConcurrentHashMap; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class AtlasAsyncImportRequest extends AtlasBaseModelObject implements Serializable { + private static final long serialVersionUID = 1L; + public static final String ASYNC_IMPORT_TYPE_NAME = "__AtlasAsyncImportRequest"; Review Comment: Constants defined in line 47-49 seem to be used/needed only in Atlas server side. If yes, please move these to server side (like repository module). ########## intg/src/main/java/org/apache/atlas/model/notification/ImportNotification.java: ########## @@ -0,0 +1,159 @@ +/** + * 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.atlas.model.notification; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; +import org.apache.atlas.model.typedef.AtlasTypesDef; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import java.io.Serializable; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * Class representing atlas import notification, extending HookNotification. + */ +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude +@JsonIgnoreProperties(ignoreUnknown = true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class ImportNotification extends HookNotification implements Serializable { Review Comment: `ImportNotification` is not instantiated anywhere. Consider following updates: - make `ImportNotification` constructor as protected - have `AtlasTypeDefImportNotification` and `AtlasEntityImportNotification ` extend `ImportNotification` - move `importId` field to `ImportNotification` ########## notification/src/main/java/org/apache/atlas/kafka/KafkaNotification.java: ########## @@ -281,9 +300,7 @@ public void sendInternal(String topic, List<String> messages, boolean isSortNeed } public void sendInternal(String topic, List<String> messages) throws NotificationException { - KafkaProducer producer = getOrCreateProducer(topic); - - sendInternalToProducer(producer, topic, messages); + sendInternal(topic, messages, SORT_NOT_NEEDED); Review Comment: ok. I get it now. `SORT_NOT_NEEDED` doesn't add much to readability, given the called method is right above. I suggest to simply send `false` here. ########## intg/src/main/java/org/apache/atlas/model/notification/ImportNotification.java: ########## @@ -0,0 +1,159 @@ +/** + * 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.atlas.model.notification; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; +import org.apache.atlas.model.typedef.AtlasTypesDef; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import java.io.Serializable; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * Class representing atlas import notification, extending HookNotification. + */ +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude +@JsonIgnoreProperties(ignoreUnknown = true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class ImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + public ImportNotification() { + } + + public ImportNotification(HookNotificationType type, String user) { + super(type, user); + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + public StringBuilder toString(StringBuilder sb) { + if (sb == null) { + sb = new StringBuilder(); + } + + sb.append("ImportNotification{"); + sb.append("type=").append(type); + sb.append(", user=").append(user); + sb.append("}"); + + return sb; + } + + /** + * Notification for type definitions import + */ + @JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonIgnoreProperties(ignoreUnknown = true) + @XmlRootElement + @XmlAccessorType(XmlAccessType.PROPERTY) + public static class AtlasTypeDefImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + @JsonProperty + private String importId; + + @JsonProperty + private AtlasTypesDef typeDefinitionMap; + + public AtlasTypeDefImportNotification() { + } + + public AtlasTypeDefImportNotification(String importId, String user, AtlasTypesDef typeDefinitionMap) { + super(HookNotificationType.IMPORT_TYPE_DEF, user); + this.typeDefinitionMap = typeDefinitionMap; + this.importId = importId; + } + + public AtlasTypesDef getTypeDefinitionMap() { + return typeDefinitionMap; + } + + public String getImportId() { + return importId; + } + + @Override + public String toString() { Review Comment: Replace `String toString()` implementation with `StringBuilder toString(StringBuilder sb)`. ########## intg/src/main/java/org/apache/atlas/model/notification/ImportNotification.java: ########## @@ -0,0 +1,159 @@ +/** + * 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.atlas.model.notification; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; +import org.apache.atlas.model.typedef.AtlasTypesDef; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import java.io.Serializable; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * Class representing atlas import notification, extending HookNotification. + */ +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude +@JsonIgnoreProperties(ignoreUnknown = true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class ImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + public ImportNotification() { + } + + public ImportNotification(HookNotificationType type, String user) { + super(type, user); + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + public StringBuilder toString(StringBuilder sb) { + if (sb == null) { + sb = new StringBuilder(); + } + + sb.append("ImportNotification{"); + sb.append("type=").append(type); + sb.append(", user=").append(user); + sb.append("}"); + + return sb; + } + + /** + * Notification for type definitions import + */ + @JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonIgnoreProperties(ignoreUnknown = true) + @XmlRootElement + @XmlAccessorType(XmlAccessType.PROPERTY) + public static class AtlasTypeDefImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + @JsonProperty + private String importId; + + @JsonProperty + private AtlasTypesDef typeDefinitionMap; + + public AtlasTypeDefImportNotification() { + } + + public AtlasTypeDefImportNotification(String importId, String user, AtlasTypesDef typeDefinitionMap) { + super(HookNotificationType.IMPORT_TYPE_DEF, user); + this.typeDefinitionMap = typeDefinitionMap; + this.importId = importId; + } + + public AtlasTypesDef getTypeDefinitionMap() { + return typeDefinitionMap; + } + + public String getImportId() { + return importId; + } + + @Override + public String toString() { + return "importId=" + importId + (typeDefinitionMap == null ? "null" : typeDefinitionMap.toString()); + } + } + + /** + * Notification for entities import + */ + @JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) + @JsonInclude + @JsonIgnoreProperties(ignoreUnknown = true) + @XmlRootElement + @XmlAccessorType(XmlAccessType.PROPERTY) + public static class AtlasEntityImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + @JsonProperty + private String importId; + + @JsonProperty + private AtlasEntityWithExtInfo entities; + + @JsonProperty + private int position; + + public AtlasEntityImportNotification() { + } + + public AtlasEntityImportNotification(String importId, String user, AtlasEntityWithExtInfo entities, int position) { + super(HookNotificationType.IMPORT_ENTITY, user); + this.entities = entities; + this.position = position; + this.importId = importId; + } + + public AtlasEntityWithExtInfo getEntities() { + return entities; + } + + public int getPosition() { + return position; + } + + public String getImportId() { + return importId; + } + + @Override + public String toString() { Review Comment: Replace `String toString()` implementation with `StringBuilder toString(StringBuilder sb)`. ########## intg/src/main/java/org/apache/atlas/model/notification/ImportNotification.java: ########## @@ -0,0 +1,159 @@ +/** + * 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.atlas.model.notification; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; +import org.apache.atlas.model.typedef.AtlasTypesDef; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import java.io.Serializable; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * Class representing atlas import notification, extending HookNotification. + */ +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude +@JsonIgnoreProperties(ignoreUnknown = true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class ImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + public ImportNotification() { + } + + public ImportNotification(HookNotificationType type, String user) { + super(type, user); + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + public StringBuilder toString(StringBuilder sb) { + if (sb == null) { + sb = new StringBuilder(); + } + + sb.append("ImportNotification{"); + sb.append("type=").append(type); + sb.append(", user=").append(user); + sb.append("}"); + + return sb; + } + + /** + * Notification for type definitions import + */ + @JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonIgnoreProperties(ignoreUnknown = true) + @XmlRootElement + @XmlAccessorType(XmlAccessType.PROPERTY) + public static class AtlasTypeDefImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + @JsonProperty + private String importId; + + @JsonProperty + private AtlasTypesDef typeDefinitionMap; + + public AtlasTypeDefImportNotification() { + } + + public AtlasTypeDefImportNotification(String importId, String user, AtlasTypesDef typeDefinitionMap) { + super(HookNotificationType.IMPORT_TYPE_DEF, user); + this.typeDefinitionMap = typeDefinitionMap; + this.importId = importId; + } + + public AtlasTypesDef getTypeDefinitionMap() { + return typeDefinitionMap; + } + + public String getImportId() { + return importId; + } + + @Override + public String toString() { + return "importId=" + importId + (typeDefinitionMap == null ? "null" : typeDefinitionMap.toString()); + } + } + + /** + * Notification for entities import + */ + @JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) + @JsonInclude + @JsonIgnoreProperties(ignoreUnknown = true) + @XmlRootElement + @XmlAccessorType(XmlAccessType.PROPERTY) + public static class AtlasEntityImportNotification extends HookNotification implements Serializable { + private static final long serialVersionUID = 1L; + + @JsonProperty + private String importId; + + @JsonProperty + private AtlasEntityWithExtInfo entities; Review Comment: `entities` => `entity` ########## notification/src/main/java/org/apache/atlas/notification/rest/RestNotification.java: ########## @@ -84,6 +84,10 @@ public void sendInternal(NotificationType type, List<String> messages) throws No } } + @Override + public void sendInternal(String topic, List<String> messages) throws NotificationException { + } Review Comment: In that case, I suggest to throw an exception (something like NotImplementedException) to capture inadvertent use of this method. ########## notification/src/main/java/org/apache/atlas/notification/spool/Spooler.java: ########## @@ -81,6 +82,10 @@ public void sendInternal(NotificationType type, List<String> messages) { } } + @Override + public void sendInternal(String topic, List<String> messages) throws NotificationException { + } Review Comment: In that case, I suggest to throw an exception (something like NotImplementedException) to capture inadvertent use of this method. ########## notification/src/test/java/org/apache/atlas/notification/spool/AtlasFileSpoolTest.java: ########## @@ -160,6 +160,10 @@ public void sendInternal(NotificationType type, List<String> messages) { publishedMessages.addAll(messages); } + @Override + public void sendInternal(String topic, List<String> messages) throws NotificationException { + } Review Comment: Ok. Add test to ensure that call to this method on `AtlasFileSpool` throws exception. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@atlas.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org