-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…5948) ### What changes were proposed in this pull request? This PR adds the server-side REST endpoint for model management. ### Why are the changes needed? This is a part of model management for Gravitino. Fix: #5817 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Add UTs for this PR.
- Loading branch information
Showing
25 changed files
with
3,006 additions
and
33 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
163 changes: 163 additions & 0 deletions
163
common/src/main/java/org/apache/gravitino/dto/model/ModelDTO.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,163 @@ | ||
/* | ||
* 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.gravitino.dto.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Map; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.gravitino.dto.AuditDTO; | ||
import org.apache.gravitino.model.Model; | ||
|
||
/** Represents a model DTO (Data Transfer Object). */ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE, force = true) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@EqualsAndHashCode | ||
public class ModelDTO implements Model { | ||
|
||
@JsonProperty("name") | ||
private String name; | ||
|
||
@JsonProperty("comment") | ||
private String comment; | ||
|
||
@JsonProperty("properties") | ||
private Map<String, String> properties; | ||
|
||
@JsonProperty("latestVersion") | ||
private int latestVersion; | ||
|
||
@JsonProperty("audit") | ||
private AuditDTO audit; | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String comment() { | ||
return comment; | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
@Override | ||
public int latestVersion() { | ||
return latestVersion; | ||
} | ||
|
||
@Override | ||
public AuditDTO auditInfo() { | ||
return audit; | ||
} | ||
|
||
/** | ||
* Creates a new builder for constructing a Model DTO. | ||
* | ||
* @return The builder. | ||
*/ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** Builder for constructing a Model DTO. */ | ||
public static class Builder { | ||
private String name; | ||
private String comment; | ||
private Map<String, String> properties; | ||
private int latestVersion; | ||
private AuditDTO audit; | ||
|
||
/** | ||
* Sets the name of the model. | ||
* | ||
* @param name The name of the model. | ||
* @return The builder. | ||
*/ | ||
public Builder withName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the comment associated with the model. | ||
* | ||
* @param comment The comment associated with the model. | ||
* @return The builder. | ||
*/ | ||
public Builder withComment(String comment) { | ||
this.comment = comment; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the properties associated with the model. | ||
* | ||
* @param properties The properties associated with the model. | ||
* @return The builder. | ||
*/ | ||
public Builder withProperties(Map<String, String> properties) { | ||
this.properties = properties; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the latest version of the model. | ||
* | ||
* @param latestVersion The latest version of the model. | ||
* @return The builder. | ||
*/ | ||
public Builder withLatestVersion(int latestVersion) { | ||
this.latestVersion = latestVersion; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the audit information associated with the model. | ||
* | ||
* @param audit The audit information associated with the model. | ||
* @return The builder. | ||
*/ | ||
public Builder withAudit(AuditDTO audit) { | ||
this.audit = audit; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the model DTO. | ||
* | ||
* @return The model DTO. | ||
*/ | ||
public ModelDTO build() { | ||
Preconditions.checkArgument(StringUtils.isNotBlank(name), "name cannot be null or empty"); | ||
Preconditions.checkArgument(latestVersion >= 0, "latestVersion cannot be negative"); | ||
Preconditions.checkArgument(audit != null, "audit cannot be null"); | ||
|
||
return new ModelDTO(name, comment, properties, latestVersion, audit); | ||
} | ||
} | ||
} |
184 changes: 184 additions & 0 deletions
184
common/src/main/java/org/apache/gravitino/dto/model/ModelVersionDTO.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,184 @@ | ||
/* | ||
* 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.gravitino.dto.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Map; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.gravitino.Audit; | ||
import org.apache.gravitino.dto.AuditDTO; | ||
import org.apache.gravitino.model.ModelVersion; | ||
|
||
/** Represents a model version DTO (Data Transfer Object). */ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE, force = true) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@EqualsAndHashCode | ||
public class ModelVersionDTO implements ModelVersion { | ||
|
||
@JsonProperty("version") | ||
private int version; | ||
|
||
@JsonProperty("comment") | ||
private String comment; | ||
|
||
@JsonProperty("aliases") | ||
private String[] aliases; | ||
|
||
@JsonProperty("uri") | ||
private String uri; | ||
|
||
@JsonProperty("properties") | ||
private Map<String, String> properties; | ||
|
||
@JsonProperty("audit") | ||
private AuditDTO audit; | ||
|
||
@Override | ||
public Audit auditInfo() { | ||
return audit; | ||
} | ||
|
||
@Override | ||
public int version() { | ||
return version; | ||
} | ||
|
||
@Override | ||
public String comment() { | ||
return comment; | ||
} | ||
|
||
@Override | ||
public String[] aliases() { | ||
return aliases; | ||
} | ||
|
||
@Override | ||
public String uri() { | ||
return uri; | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
/** | ||
* Creates a new builder for constructing a Model Version DTO. | ||
* | ||
* @return The builder. | ||
*/ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** Builder for constructing a Model Version DTO. */ | ||
public static class Builder { | ||
private int version; | ||
private String comment; | ||
private String[] aliases; | ||
private String uri; | ||
private Map<String, String> properties; | ||
private AuditDTO audit; | ||
|
||
/** | ||
* Sets the version number of the model version. | ||
* | ||
* @param version The version number. | ||
* @return The builder. | ||
*/ | ||
public Builder withVersion(int version) { | ||
this.version = version; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the comment of the model version. | ||
* | ||
* @param comment The comment. | ||
* @return The builder. | ||
*/ | ||
public Builder withComment(String comment) { | ||
this.comment = comment; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the aliases of the model version. | ||
* | ||
* @param aliases The aliases. | ||
* @return The builder. | ||
*/ | ||
public Builder withAliases(String[] aliases) { | ||
this.aliases = aliases; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the URI of the model version. | ||
* | ||
* @param uri The URI. | ||
* @return The builder. | ||
*/ | ||
public Builder withUri(String uri) { | ||
this.uri = uri; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the properties of the model version. | ||
* | ||
* @param properties The properties. | ||
* @return The builder. | ||
*/ | ||
public Builder withProperties(Map<String, String> properties) { | ||
this.properties = properties; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the audit information of the model version. | ||
* | ||
* @param audit The audit information. | ||
* @return The builder. | ||
*/ | ||
public Builder withAudit(AuditDTO audit) { | ||
this.audit = audit; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the Model Version DTO. | ||
* | ||
* @return The Model Version DTO. | ||
*/ | ||
public ModelVersionDTO build() { | ||
Preconditions.checkArgument(version >= 0, "Version must be non-negative"); | ||
Preconditions.checkArgument(StringUtils.isNotBlank(uri), "URI cannot be null or empty"); | ||
Preconditions.checkArgument(audit != null, "Audit cannot be null"); | ||
|
||
return new ModelVersionDTO(version, comment, aliases, uri, properties, audit); | ||
} | ||
} | ||
} |
Oops, something went wrong.