Skip to content

Commit

Permalink
HDDS-12041. Add ozone repair scm cert command and its subcommand
Browse files Browse the repository at this point in the history
HDDS-12041. Add ozone repair scm cert command and its subcommand

Added license header to CertRepair
  • Loading branch information
sarvekshayr committed Jan 9, 2025
1 parent 71de2a2 commit bb02fbb
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.hadoop.ozone.repair.scm;

import org.apache.hadoop.hdds.cli.RepairSubcommand;
import org.apache.hadoop.ozone.repair.scm.cert.CertRepair;
import org.kohsuke.MetaInfServices;
import picocli.CommandLine;

/**
* Ozone Repair CLI for SCM.
*/
@CommandLine.Command(name = "scm",
description = "Operational tool to repair SCM.",
subcommands = {
CertRepair.class,
}
)
@MetaInfServices(RepairSubcommand.class)
public class SCMRepair implements RepairSubcommand {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.hadoop.ozone.repair.scm.cert;

import picocli.CommandLine;

/**
* A dedicated subcommand for all certificate related repairs on SCM.
*/

@CommandLine.Command(name = "cert",
description = "Subcommand for all certificate related repairs on SCM",
subcommands = {
RecoverSCMCertificate.class
}
)
public class CertRepair {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.ozone.repair;
package org.apache.hadoop.ozone.repair.scm.cert;

import org.apache.hadoop.hdds.cli.RepairSubcommand;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.security.SecurityConfig;
import org.apache.hadoop.hdds.security.x509.certificate.authority.CAType;
Expand All @@ -31,7 +30,8 @@
import org.apache.hadoop.ozone.debug.DBDefinitionFactory;
import org.apache.hadoop.ozone.debug.RocksDBUtils;
import java.security.cert.CertificateFactory;
import org.kohsuke.MetaInfServices;

import org.apache.hadoop.ozone.repair.RepairTool;
import org.rocksdb.ColumnFamilyDescriptor;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksDBException;
Expand Down Expand Up @@ -63,21 +63,19 @@
* and private keys of the SCM are intact.
*/
@CommandLine.Command(
name = "cert-recover",
name = "recover",
description = "Recover Deleted SCM Certificate from RocksDB")
@MetaInfServices(RepairSubcommand.class)
public class RecoverSCMCertificate extends RepairTool implements RepairSubcommand {

public class RecoverSCMCertificate extends RepairTool {
@CommandLine.Option(names = {"--db"},
required = true,
description = "SCM DB Path")
private String dbPath;

@CommandLine.ParentCommand
private OzoneRepair parent;

@Override
public void execute() throws Exception {
if (checkIfServiceIsRunning("SCM")) {
return;
}
dbPath = removeTrailingSlashIfNeeded(dbPath);
String tableName = VALID_SCM_CERTS.getName();
DBDefinition dbDefinition =
Expand All @@ -96,7 +94,7 @@ public void execute() throws Exception {
try (ManagedRocksDB db = ManagedRocksDB.openReadOnly(dbPath, cfDescList,
cfHandleList)) {
cfHandle = getColumnFamilyHandle(cfHandleList, tableNameBytes);
SecurityConfig securityConfig = new SecurityConfig(parent.getOzoneConf());
SecurityConfig securityConfig = new SecurityConfig(getOzoneConf());

Map<BigInteger, X509Certificate> allCerts = getAllCerts(columnFamilyDefinition, cfHandle, db);
info("All Certs in DB : %s", allCerts.keySet());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

/**
* SCM Cert Repair tools.
*/
package org.apache.hadoop.ozone.repair.scm.cert;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

/**
* SCM related repair tools.
*/
package org.apache.hadoop.ozone.repair.scm;

0 comments on commit bb02fbb

Please sign in to comment.