MDStoreManager model classes imported from dnet-hadoop project

This commit is contained in:
Claudio Atzori 2021-05-10 14:02:18 +02:00
parent eb9aecfcf9
commit 5dc52ed56b
5 changed files with 193 additions and 30 deletions

View File

@ -5,7 +5,7 @@
<groupId>eu.dnetlib.dhp</groupId> <groupId>eu.dnetlib.dhp</groupId>
<artifactId>dhp-schemas</artifactId> <artifactId>dhp-schemas</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>2.3.7-SNAPSHOT</version> <version>2.3.6-SNAPSHOT</version>
<licenses> <licenses>
<license> <license>

View File

@ -2,12 +2,11 @@
package eu.dnetlib.dhp.schema.mdstore; package eu.dnetlib.dhp.schema.mdstore;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.persistence.Column; import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity @Entity
@Table(name = "mdstores") @Table(name = "mdstores")
@ -38,6 +37,13 @@ public class MDStore implements Serializable {
@Column(name = "api_id") @Column(name = "api_id")
private String apiId; private String apiId;
@Column(name = "hdfs_path")
private String hdfsPath;
@Column(name = "creation_date")
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
public String getId() { public String getId() {
return id; return id;
} }
@ -94,9 +100,28 @@ public class MDStore implements Serializable {
this.apiId = apiId; this.apiId = apiId;
} }
public String getHdfsPath() {
return hdfsPath;
}
public void setHdfsPath(final String hdfsPath) {
this.hdfsPath = hdfsPath;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(final Date creationDate) {
this.creationDate = creationDate;
}
public static MDStore newInstance( public static MDStore newInstance(
final String format, final String layout, final String interpretation) { final String format,
return newInstance(format, layout, interpretation, null, null, null); final String layout,
final String interpretation,
final String hdfsBasePath) {
return newInstance(format, layout, interpretation, null, null, null, hdfsBasePath);
} }
public static MDStore newInstance( public static MDStore newInstance(
@ -105,15 +130,48 @@ public class MDStore implements Serializable {
final String interpretation, final String interpretation,
final String dsName, final String dsName,
final String dsId, final String dsId,
final String apiId) { final String apiId,
final String hdfsBasePath) {
final String mdId = "md-" + UUID.randomUUID();
final MDStore md = new MDStore(); final MDStore md = new MDStore();
md.setId("md-" + UUID.randomUUID()); md.setId(mdId);
md.setFormat(format); md.setFormat(format);
md.setLayout(layout); md.setLayout(layout);
md.setInterpretation(interpretation); md.setInterpretation(interpretation);
md.setCreationDate(new Date());
md.setDatasourceName(dsName); md.setDatasourceName(dsName);
md.setDatasourceId(dsId); md.setDatasourceId(dsId);
md.setApiId(apiId); md.setApiId(apiId);
md.setHdfsPath(String.format("%s/%s", hdfsBasePath, mdId));
return md; return md;
} }
@Override
public String toString() {
return String
.format(
"MDStore [id=%s, format=%s, layout=%s, interpretation=%s, datasourceName=%s, datasourceId=%s, apiId=%s, hdfsPath=%s, creationDate=%s]",
id, format, layout, interpretation, datasourceName, datasourceId, apiId, hdfsPath, creationDate);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof MDStore)) {
return false;
}
final MDStore other = (MDStore) obj;
return Objects.equals(id, other.id);
}
} }

View File

@ -2,6 +2,7 @@
package eu.dnetlib.dhp.schema.mdstore; package eu.dnetlib.dhp.schema.mdstore;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -48,4 +49,26 @@ public class MDStoreCurrentVersion implements Serializable {
public static MDStoreCurrentVersion newInstance(final MDStoreVersion v) { public static MDStoreCurrentVersion newInstance(final MDStoreVersion v) {
return newInstance(v.getMdstore(), v.getId()); return newInstance(v.getMdstore(), v.getId());
} }
@Override
public String toString() {
return String.format("MDStoreCurrentVersion [mdstore=%s, currentVersion=%s]", mdstore, currentVersion);
}
@Override
public int hashCode() {
return Objects.hash(currentVersion, mdstore);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof MDStoreCurrentVersion)) {
return false;
}
final MDStoreCurrentVersion other = (MDStoreCurrentVersion) obj;
return Objects.equals(currentVersion, other.currentVersion) && Objects.equals(mdstore, other.mdstore);
}
} }

View File

@ -3,13 +3,9 @@ package eu.dnetlib.dhp.schema.mdstore;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Objects;
import javax.persistence.Column; import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity @Entity
@Table(name = "mdstore_versions") @Table(name = "mdstore_versions")
@ -38,15 +34,22 @@ public class MDStoreVersion implements Serializable {
@Column(name = "size") @Column(name = "size")
private long size = 0; private long size = 0;
public static MDStoreVersion newInstance(final String mdId, final boolean writing) { @Column(name = "hdfs_path")
final MDStoreVersion t = new MDStoreVersion(); private String hdfsPath;
t.setId(mdId + "-" + new Date().getTime());
t.setMdstore(mdId); public static MDStoreVersion newInstance(final String mdId, final boolean writing, final String hdfsBasePath) {
t.setLastUpdate(null); final MDStoreVersion v = new MDStoreVersion();
t.setWriting(writing);
t.setReadCount(0); final String versionId = mdId + "-" + new Date().getTime();
t.setSize(0); v.setId(versionId);
return t; v.setMdstore(mdId);
v.setLastUpdate(null);
v.setWriting(writing);
v.setReadCount(0);
v.setSize(0);
v.setHdfsPath(String.format("%s/%s/%s", hdfsBasePath, mdId, versionId));
return v;
} }
public String getId() { public String getId() {
@ -96,4 +99,37 @@ public class MDStoreVersion implements Serializable {
public void setSize(final long size) { public void setSize(final long size) {
this.size = size; this.size = size;
} }
public String getHdfsPath() {
return hdfsPath;
}
public void setHdfsPath(final String hdfsPath) {
this.hdfsPath = hdfsPath;
}
@Override
public String toString() {
return String
.format(
"MDStoreVersion [id=%s, mdstore=%s, writing=%s, readCount=%s, lastUpdate=%s, size=%s, hdfsPath=%s]", id,
mdstore, writing, readCount, lastUpdate, size, hdfsPath);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof MDStoreVersion)) {
return false;
}
final MDStoreVersion other = (MDStoreVersion) obj;
return Objects.equals(id, other.id);
}
} }

View File

@ -3,13 +3,9 @@ package eu.dnetlib.dhp.schema.mdstore;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Objects;
import javax.persistence.Column; import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity @Entity
@Table(name = "mdstores_with_info") @Table(name = "mdstores_with_info")
@ -43,6 +39,10 @@ public class MDStoreWithInfo implements Serializable {
@Column(name = "current_version") @Column(name = "current_version")
private String currentVersion; private String currentVersion;
@Column(name = "creation_date")
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
@Column(name = "lastupdate") @Column(name = "lastupdate")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date lastUpdate; private Date lastUpdate;
@ -53,6 +53,9 @@ public class MDStoreWithInfo implements Serializable {
@Column(name = "n_versions") @Column(name = "n_versions")
private long numberOfVersions = 0; private long numberOfVersions = 0;
@Column(name = "hdfs_path")
private String hdfsPath;
public String getId() { public String getId() {
return id; return id;
} }
@ -117,6 +120,14 @@ public class MDStoreWithInfo implements Serializable {
this.currentVersion = currentVersion; this.currentVersion = currentVersion;
} }
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(final Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastUpdate() { public Date getLastUpdate() {
return lastUpdate; return lastUpdate;
} }
@ -140,4 +151,39 @@ public class MDStoreWithInfo implements Serializable {
public void setNumberOfVersions(final long numberOfVersions) { public void setNumberOfVersions(final long numberOfVersions) {
this.numberOfVersions = numberOfVersions; this.numberOfVersions = numberOfVersions;
} }
public String getHdfsPath() {
return hdfsPath;
}
public void setHdfsPath(final String hdfsPath) {
this.hdfsPath = hdfsPath;
}
@Override
public String toString() {
return String
.format(
"MDStoreWithInfo [id=%s, format=%s, layout=%s, interpretation=%s, datasourceName=%s, datasourceId=%s, apiId=%s, currentVersion=%s, creationDate=%s, lastUpdate=%s, size=%s, numberOfVersions=%s, hdfsPath=%s]",
id, format, layout, interpretation, datasourceName, datasourceId, apiId, currentVersion, creationDate,
lastUpdate, size, numberOfVersions, hdfsPath);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof MDStoreWithInfo)) {
return false;
}
final MDStoreWithInfo other = (MDStoreWithInfo) obj;
return Objects.equals(id, other.id);
}
} }