|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.gravitino.cli.commands; |
| 21 | + |
| 22 | +import org.apache.gravitino.NameIdentifier; |
| 23 | +import org.apache.gravitino.cli.ErrorMessages; |
| 24 | +import org.apache.gravitino.client.GravitinoClient; |
| 25 | +import org.apache.gravitino.exceptions.NoSuchCatalogException; |
| 26 | +import org.apache.gravitino.exceptions.NoSuchFilesetException; |
| 27 | +import org.apache.gravitino.exceptions.NoSuchMetalakeException; |
| 28 | +import org.apache.gravitino.exceptions.NoSuchSchemaException; |
| 29 | +import org.apache.gravitino.file.FilesetChange; |
| 30 | + |
| 31 | +/** Set a property of a fileset. */ |
| 32 | +public class SetFilesetProperty extends Command { |
| 33 | + |
| 34 | + protected final String metalake; |
| 35 | + protected final String catalog; |
| 36 | + protected final String schema; |
| 37 | + protected final String fileset; |
| 38 | + protected final String property; |
| 39 | + protected final String value; |
| 40 | + |
| 41 | + /** |
| 42 | + * Set a property of a schema. |
| 43 | + * |
| 44 | + * @param url The URL of the Gravitino server. |
| 45 | + * @param ignoreVersions If true don't check the client/server versions match. |
| 46 | + * @param metalake The name of the metalake. |
| 47 | + * @param catalog The name of the catalog. |
| 48 | + * @param schema The name of the schema. |
| 49 | + * @param fileset The name of the fileset. |
| 50 | + * @param property The name of the property. |
| 51 | + * @param value The value of the property. |
| 52 | + */ |
| 53 | + public SetFilesetProperty( |
| 54 | + String url, |
| 55 | + boolean ignoreVersions, |
| 56 | + String metalake, |
| 57 | + String catalog, |
| 58 | + String schema, |
| 59 | + String fileset, |
| 60 | + String property, |
| 61 | + String value) { |
| 62 | + super(url, ignoreVersions); |
| 63 | + this.metalake = metalake; |
| 64 | + this.catalog = catalog; |
| 65 | + this.schema = schema; |
| 66 | + this.fileset = fileset; |
| 67 | + this.property = property; |
| 68 | + this.value = value; |
| 69 | + } |
| 70 | + |
| 71 | + /** Set a property of a fileset. */ |
| 72 | + @Override |
| 73 | + public void handle() { |
| 74 | + try { |
| 75 | + NameIdentifier name = NameIdentifier.of(schema, fileset); |
| 76 | + GravitinoClient client = buildClient(metalake); |
| 77 | + FilesetChange change = FilesetChange.setProperty(property, value); |
| 78 | + client.loadCatalog(catalog).asFilesetCatalog().alterFileset(name, change); |
| 79 | + } catch (NoSuchMetalakeException err) { |
| 80 | + System.err.println(ErrorMessages.UNKNOWN_METALAKE); |
| 81 | + return; |
| 82 | + } catch (NoSuchCatalogException err) { |
| 83 | + System.err.println(ErrorMessages.UNKNOWN_CATALOG); |
| 84 | + return; |
| 85 | + } catch (NoSuchSchemaException err) { |
| 86 | + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); |
| 87 | + return; |
| 88 | + } catch (NoSuchFilesetException err) { |
| 89 | + System.err.println(ErrorMessages.UNKNOWN_FILESET); |
| 90 | + return; |
| 91 | + } catch (Exception exp) { |
| 92 | + System.err.println(exp.getMessage()); |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + System.out.println(schema + " property set."); |
| 97 | + } |
| 98 | +} |
0 commit comments