123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*
- 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.
- */
- #include <google/protobuf/stubs/common.h>
- #include <unistd.h>
- #include "tools_common.h"
- void usage(){
- std::cout << "Usage: hdfs_disallowSnapshot [OPTION] PATH"
- << std::endl
- << std::endl << "Disallowing snapshots of a directory at PATH to be created."
- << std::endl << "All snapshots of the directory must be deleted before disallowing snapshots."
- << std::endl
- << std::endl << " -h display this help and exit"
- << std::endl
- << std::endl << "Examples:"
- << std::endl << "hdfs_disallowSnapshot hdfs://localhost.localdomain:8020/dir"
- << std::endl << "hdfs_disallowSnapshot /dir1/dir2"
- << std::endl;
- }
- int main(int argc, char *argv[]) {
- //We should have at least 2 arguments
- if (argc < 2) {
- usage();
- exit(EXIT_FAILURE);
- }
- int input;
- //Using GetOpt to read in the values
- opterr = 0;
- while ((input = getopt(argc, argv, "Rh")) != -1) {
- switch (input)
- {
- case 'h':
- usage();
- exit(EXIT_SUCCESS);
- case '?':
- if (isprint(optopt))
- std::cerr << "Unknown option `-" << (char) optopt << "'." << std::endl;
- else
- std::cerr << "Unknown option character `" << (char) optopt << "'." << std::endl;
- usage();
- exit(EXIT_FAILURE);
- default:
- exit(EXIT_FAILURE);
- }
- }
- std::string uri_path = argv[optind];
- //Building a URI object from the given uri_path
- hdfs::optional<hdfs::URI> uri = hdfs::URI::parse_from_string(uri_path);
- if (!uri) {
- std::cerr << "Malformed URI: " << uri_path << std::endl;
- exit(EXIT_FAILURE);
- }
- std::shared_ptr<hdfs::FileSystem> fs = hdfs::doConnect(uri.value(), false);
- if (!fs) {
- std::cerr << "Could not connect the file system. " << std::endl;
- exit(EXIT_FAILURE);
- }
- hdfs::Status status = fs->DisallowSnapshot(uri->get_path());
- if (!status.ok()) {
- std::cerr << "Error: " << status.ToString() << std::endl;
- exit(EXIT_FAILURE);
- }
- // Clean up static data and prevent valgrind memory leaks
- google::protobuf::ShutdownProtobufLibrary();
- return 0;
- }
|