-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'azkaban:master' into zhzeng/extract-yarn-methods-to-utils
- Loading branch information
Showing
20 changed files
with
933 additions
and
34 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
61 changes: 61 additions & 0 deletions
61
azkaban-common/src/main/java/azkaban/imagemgmt/daos/RampRuleDao.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,61 @@ | ||
/* | ||
* Copyright 2022 LinkedIn Corp. | ||
* | ||
* 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://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 azkaban.imagemgmt.daos; | ||
|
||
import azkaban.imagemgmt.models.ImageRampRule; | ||
|
||
|
||
/** | ||
* Data access object (DAO) for accessing image ramp rule that deny an image ramping version for flows. | ||
* This interface defines add/remove/modify/get an image ramp rule. | ||
* */ | ||
public interface RampRuleDao { | ||
|
||
/** | ||
* Query table ramp_rules to check whether a HPFlowRule . | ||
* | ||
* @param ruleName - ruleName in {@see ImageRampRule} | ||
* @return true - if ramp rule is setup for HP Flows, denying any ramp up plan; | ||
* false - if ramp rule is normal rule, regulate only on certain image version. | ||
*/ | ||
boolean isHPFlowRule(final String ruleName); | ||
|
||
/** | ||
* Insert Image Ramp Rule metadata into DB. | ||
* | ||
* @param rule - RampRule model created in {@see ImageRampRuleServiceImpl} | ||
* @return int - id of the DB entry | ||
* @throws azkaban.imagemgmt.exception.ImageMgmtDaoException | ||
*/ | ||
int addRampRule(final ImageRampRule rule); | ||
|
||
/** | ||
* Query table ramp_rules to get owners of Ramp rule. | ||
* | ||
* @param ruleName - ruleName in {@see ImageRampRule} | ||
* @return owners of the ramp rule. | ||
*/ | ||
String getOwners(final String ruleName); | ||
|
||
/** | ||
* delete the ramp_rules to get owners of Ramp rule. | ||
* | ||
* @param ruleName - ruleName in {@see ImageRampRule} | ||
* @throws azkaban.imagemgmt.exception.ImageMgmtDaoException | ||
*/ | ||
void deleteRampRule(final String ruleName); | ||
|
||
} |
137 changes: 137 additions & 0 deletions
137
azkaban-common/src/main/java/azkaban/imagemgmt/daos/RampRuleDaoImpl.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,137 @@ | ||
/* | ||
* Copyright 2022 LinkedIn Corp. | ||
* | ||
* 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://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 azkaban.imagemgmt.daos; | ||
|
||
import azkaban.db.DatabaseOperator; | ||
import azkaban.imagemgmt.exception.ErrorCode; | ||
import azkaban.imagemgmt.exception.ImageMgmtDaoException; | ||
import azkaban.imagemgmt.models.ImageRampRule; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.apache.commons.dbutils.ResultSetHandler; | ||
import org.apache.log4j.Logger; | ||
import org.bouncycastle.util.Strings; | ||
|
||
/** | ||
* Dao Implementation for access DB of table ramp_rules. | ||
* Create/update/delete/get RampRule or partial RampRule metadata. {@link ImageRampRule} | ||
* */ | ||
@Singleton | ||
public class RampRuleDaoImpl implements RampRuleDao { | ||
private static final Logger LOG = Logger.getLogger(RampRuleDaoImpl.class); | ||
private final DatabaseOperator databaseOperator; | ||
|
||
private static String INSERT_RAMP_RULE = "INSERT into ramp_rules " | ||
+ "(rule_name, image_name, image_version, owners, is_HP, created_by, created_on, modified_by, modified_on)" | ||
+ " values (?, ?, ?, ?, ?, ?, ?, ?, ?)"; | ||
|
||
@Inject | ||
public RampRuleDaoImpl(final DatabaseOperator databaseOperator) { | ||
this.databaseOperator = databaseOperator; | ||
} | ||
|
||
@Override | ||
public boolean isHPFlowRule(final String ruleName) { | ||
return false; | ||
} | ||
|
||
/** | ||
* Insert new ramp rule into DB, check if duplicate ruleName exists first | ||
* | ||
* @param rampRule | ||
* @throws ImageMgmtDaoException | ||
* */ | ||
@Override | ||
public int addRampRule(final ImageRampRule rampRule) { | ||
try { | ||
// duplicated rule should be forbidden as client side error, which needs a separate check to | ||
// avoid it falls into normal SQL Exception as server error. | ||
List<ImageRampRule> rampRules = databaseOperator.query( | ||
FetchRampRuleHandler.FETCH_RAMP_RULE_BY_ID, new FetchRampRuleHandler(), rampRule.getRuleName()); | ||
if (!rampRules.isEmpty()) { | ||
LOG.error("Error in create ramp rule on duplicate ruleName: " + rampRule.getRuleName()); | ||
throw new ImageMgmtDaoException(ErrorCode.BAD_REQUEST, | ||
"Error in create ramp rule on duplicate ruleName: " + rampRule.getRuleName()); | ||
} | ||
return this.databaseOperator.update(INSERT_RAMP_RULE, | ||
rampRule.getRuleName(), | ||
rampRule.getImageName(), | ||
rampRule.getImageVersion(), | ||
rampRule.getOwners(), | ||
rampRule.isHPRule(), | ||
rampRule.getCreatedBy(), | ||
Timestamp.valueOf(LocalDateTime.now()), | ||
rampRule.getCreatedBy(), | ||
Timestamp.valueOf(LocalDateTime.now())); | ||
} catch (SQLException e) { | ||
LOG.error("Error in create ramp rule on DB" + rampRule); | ||
throw new ImageMgmtDaoException(ErrorCode.INTERNAL_SERVER_ERROR, | ||
"Error creating ramp rule " + rampRule.getRuleName() + "with " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public String getOwners(final String ruleName) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void deleteRampRule(final String ruleName) { | ||
|
||
} | ||
|
||
public static class FetchRampRuleHandler implements ResultSetHandler<List<ImageRampRule>> { | ||
|
||
private static final String FETCH_RAMP_RULE_BY_ID = | ||
"SELECT rule_name, image_name, image_version, owners, is_HP" | ||
+ " FROM ramp_rules WHERE rule_name = ?"; | ||
|
||
@Override | ||
public List<ImageRampRule> handle(final ResultSet rs) throws SQLException { | ||
if (!rs.next()) { | ||
return Collections.emptyList(); | ||
} | ||
final List<ImageRampRule> imageRampRules = new ArrayList<>(); | ||
do { | ||
final String ruleName = rs.getString("rule_name"); | ||
final String imageName = rs.getString("image_name"); | ||
final String imageVersion = rs.getString("image_version"); | ||
final String owners = rs.getString("owners"); | ||
final boolean isHP = rs.getBoolean("is_HP"); | ||
Set<String> ownerLists = new HashSet<>(Arrays.asList(Strings.split(owners, ','))); | ||
final ImageRampRule imageRampRule = new ImageRampRule.Builder() | ||
.setRuleName(ruleName) | ||
.setImageName(imageName) | ||
.setImageVersion(imageVersion) | ||
.setOwners(ownerLists) | ||
.setHPRule(isHP) | ||
.build(); | ||
imageRampRules.add(imageRampRule); | ||
} while (rs.next()); | ||
return imageRampRules; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
azkaban-common/src/main/java/azkaban/imagemgmt/dto/ImageRampRuleRequestDTO.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,66 @@ | ||
/* | ||
* Copyright 2022 LinkedIn Corp. | ||
* | ||
* 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://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 azkaban.imagemgmt.dto; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
/** | ||
* This class represents ImageRampRule Request when receiving request body from user. | ||
* */ | ||
public class ImageRampRuleRequestDTO extends BaseDTO { | ||
// Represents the name of the Ramp rule | ||
@JsonProperty("ruleName") | ||
@NotBlank(message = "ruleName cannot be blank.", groups = ValidationOnCreate.class) | ||
@NotNull(message = "ruleName cannot be null.") | ||
private String ruleName; | ||
// Represents the name of the image type for the rule | ||
@JsonProperty("imageName") | ||
@NotBlank(message = "imageName cannot be blank.", groups = {ValidationOnCreate.class}) | ||
@NotNull(message = "imageName cannot be null.") | ||
private String imageName; | ||
// Represents the name of the image version for the rule | ||
@JsonProperty("imageVersion") | ||
@NotBlank(message = "imageVersion cannot be blank.", groups = {ValidationOnCreate.class}) | ||
@NotNull(message = "imageVersion cannot be null.") | ||
private String imageVersion; | ||
|
||
public void setRuleName(String ruleName) { | ||
this.ruleName = ruleName; | ||
} | ||
|
||
public void setImageName(String imageName) { | ||
this.imageName = imageName; | ||
} | ||
|
||
public void setImageVersion(String imageVersion) { | ||
this.imageVersion = imageVersion; | ||
} | ||
|
||
public String getRuleName() { | ||
return ruleName; | ||
} | ||
|
||
public String getImageName() { | ||
return imageName; | ||
} | ||
|
||
public String getImageVersion() { | ||
return imageVersion; | ||
} | ||
|
||
} |
Oops, something went wrong.