This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a series of actions for EC policy (#1937)
- Loading branch information
Showing
5 changed files
with
247 additions
and
1 deletion.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...port/smart-hadoop-3.1/src/main/java/org/smartdata/hdfs/action/AddErasureCodingPolicy.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 @@ | ||
/** | ||
* 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.smartdata.hdfs.action; | ||
|
||
import org.apache.hadoop.hdfs.protocol.AddErasureCodingPolicyResponse; | ||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; | ||
import org.apache.hadoop.io.erasurecode.ECSchema; | ||
import org.smartdata.action.ActionException; | ||
import org.smartdata.action.annotation.ActionSignature; | ||
import org.smartdata.conf.SmartConf; | ||
import org.smartdata.hdfs.HadoopUtil; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* An action to add an EC policy. | ||
*/ | ||
@ActionSignature( | ||
actionId = "addec", | ||
displayName = "addec", | ||
usage = AddErasureCodingPolicy.CODEC_NAME + " $codeName" + | ||
AddErasureCodingPolicy.DATA_UNITS_NUM + " $dataNum" + | ||
AddErasureCodingPolicy.PARITY_UNITS_NUM + " $parityNum" + | ||
AddErasureCodingPolicy.CELL_SIZE + " $cellSize" | ||
) | ||
public class AddErasureCodingPolicy extends HdfsAction { | ||
public static final String CODEC_NAME = "-codec"; | ||
public static final String DATA_UNITS_NUM = "-dataNum"; | ||
public static final String PARITY_UNITS_NUM = "-parityNum"; | ||
public static final String CELL_SIZE = "-cellSize"; | ||
private SmartConf conf; | ||
private String policyName; | ||
private String codecName; | ||
private int numDataUnits; | ||
private int numParityUnits; | ||
private int cellSize; | ||
|
||
@Override | ||
public void init(Map<String, String> args) { | ||
super.init(args); | ||
this.conf = getContext().getConf(); | ||
this.codecName = args.get(CODEC_NAME); | ||
this.numDataUnits = Integer.parseInt(args.get(DATA_UNITS_NUM)); | ||
this.numParityUnits = Integer.parseInt(args.get(PARITY_UNITS_NUM)); | ||
this.cellSize = Integer.parseInt(args.get(CELL_SIZE)); | ||
} | ||
|
||
@Override | ||
public void execute() throws Exception { | ||
this.setDfsClient(HadoopUtil.getDFSClient( | ||
HadoopUtil.getNameNodeUri(conf), conf)); | ||
if (codecName == null || codecName.isEmpty() || | ||
numDataUnits <= 0 || numParityUnits <= 0 || cellSize <= 0) { | ||
throw new ActionException("Illegal EC policy Schema!"); | ||
} | ||
ECSchema ecSchema = new ECSchema(codecName, numDataUnits, numParityUnits); | ||
ErasureCodingPolicy ecPolicy = new ErasureCodingPolicy(ecSchema, cellSize); | ||
AddErasureCodingPolicyResponse addEcResponse = | ||
dfsClient.addErasureCodingPolicies(new ErasureCodingPolicy[]{ecPolicy})[0]; | ||
if (addEcResponse.isSucceed()) { | ||
appendResult(String.format("EC policy named %s is added successfully!", | ||
addEcResponse.getPolicy().getName())); | ||
} else { | ||
appendResult(String.format("Failed to add the given EC policy!")); | ||
throw new ActionException(addEcResponse.getErrorMsg()); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
.../smart-hadoop-3.1/src/main/java/org/smartdata/hdfs/action/DisableErasureCodingPolicy.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,53 @@ | ||
/** | ||
* 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.smartdata.hdfs.action; | ||
|
||
import org.smartdata.action.annotation.ActionSignature; | ||
import org.smartdata.conf.SmartConf; | ||
import org.smartdata.hdfs.HadoopUtil; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* An action to disable an EC policy. | ||
*/ | ||
@ActionSignature( | ||
actionId = "disableec", | ||
displayName = "disableec", | ||
usage = DisableErasureCodingPolicy.EC_POLICY_NAME + " $policy" | ||
) | ||
public class DisableErasureCodingPolicy extends HdfsAction { | ||
public static final String EC_POLICY_NAME = "-policy"; | ||
private SmartConf conf; | ||
private String policyName; | ||
|
||
@Override | ||
public void init(Map<String, String> args) { | ||
super.init(args); | ||
this.conf = getContext().getConf(); | ||
this.policyName = args.get(EC_POLICY_NAME); | ||
} | ||
|
||
@Override | ||
public void execute() throws Exception { | ||
this.setDfsClient(HadoopUtil.getDFSClient( | ||
HadoopUtil.getNameNodeUri(conf), conf)); | ||
dfsClient.disableErasureCodingPolicy(policyName); | ||
appendResult(String.format("The EC policy named %s is disabled!", policyName)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...t/smart-hadoop-3.1/src/main/java/org/smartdata/hdfs/action/EnableErasureCodingPolicy.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,53 @@ | ||
/** | ||
* 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.smartdata.hdfs.action; | ||
|
||
import org.smartdata.action.annotation.ActionSignature; | ||
import org.smartdata.conf.SmartConf; | ||
import org.smartdata.hdfs.HadoopUtil; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* An action to enable an EC policy. | ||
*/ | ||
@ActionSignature( | ||
actionId = "enableec", | ||
displayName = "enableec", | ||
usage = EnableErasureCodingPolicy.EC_POLICY_NAME + " $policy" | ||
) | ||
public class EnableErasureCodingPolicy extends HdfsAction { | ||
public static final String EC_POLICY_NAME = "-policy"; | ||
private SmartConf conf; | ||
private String policyName; | ||
|
||
@Override | ||
public void init(Map<String, String> args) { | ||
super.init(args); | ||
this.conf = getContext().getConf(); | ||
this.policyName = args.get(EC_POLICY_NAME); | ||
} | ||
|
||
@Override | ||
public void execute() throws Exception { | ||
this.setDfsClient(HadoopUtil.getDFSClient( | ||
HadoopUtil.getNameNodeUri(conf), conf)); | ||
dfsClient.enableErasureCodingPolicy(policyName); | ||
appendResult(String.format("The EC policy named %s is enabled!", policyName)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...t/smart-hadoop-3.1/src/main/java/org/smartdata/hdfs/action/RemoveErasureCodingPolicy.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,53 @@ | ||
/** | ||
* 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.smartdata.hdfs.action; | ||
|
||
import org.smartdata.action.annotation.ActionSignature; | ||
import org.smartdata.conf.SmartConf; | ||
import org.smartdata.hdfs.HadoopUtil; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* An action to remove an EC policy. | ||
*/ | ||
@ActionSignature( | ||
actionId = "removeec", | ||
displayName = "removeec", | ||
usage = RemoveErasureCodingPolicy.EC_POLICY_NAME + " $policy" | ||
) | ||
public class RemoveErasureCodingPolicy extends HdfsAction { | ||
public static final String EC_POLICY_NAME = "-policy"; | ||
private SmartConf conf; | ||
private String policyName; | ||
|
||
@Override | ||
public void init(Map<String, String> args) { | ||
super.init(args); | ||
this.conf = getContext().getConf(); | ||
this.policyName = args.get(EC_POLICY_NAME); | ||
} | ||
|
||
@Override | ||
public void execute() throws Exception { | ||
this.setDfsClient(HadoopUtil.getDFSClient( | ||
HadoopUtil.getNameNodeUri(conf), conf)); | ||
dfsClient.removeErasureCodingPolicy(policyName); | ||
appendResult(String.format("The EC policy named %s is removed!", policyName)); | ||
} | ||
} |
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