|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package org.apache.cloudstack.api.command.admin.config; |
| 18 | + |
| 19 | +import org.apache.cloudstack.api.APICommand; |
| 20 | +import org.apache.cloudstack.api.ApiArgValidator; |
| 21 | +import org.apache.cloudstack.api.ApiConstants; |
| 22 | +import org.apache.cloudstack.api.ApiErrorCode; |
| 23 | +import org.apache.cloudstack.api.BaseCmd; |
| 24 | +import org.apache.cloudstack.api.Parameter; |
| 25 | +import org.apache.cloudstack.api.ServerApiException; |
| 26 | +import org.apache.cloudstack.api.response.ImageStoreResponse; |
| 27 | +import org.apache.cloudstack.framework.config.ConfigKey; |
| 28 | +import org.apache.log4j.Logger; |
| 29 | + |
| 30 | +import org.apache.cloudstack.api.response.AccountResponse; |
| 31 | +import org.apache.cloudstack.api.response.ClusterResponse; |
| 32 | +import org.apache.cloudstack.api.response.ConfigurationResponse; |
| 33 | +import org.apache.cloudstack.api.response.DomainResponse; |
| 34 | +import org.apache.cloudstack.api.response.StoragePoolResponse; |
| 35 | +import org.apache.cloudstack.api.response.ZoneResponse; |
| 36 | +import org.apache.cloudstack.config.Configuration; |
| 37 | + |
| 38 | +import com.cloud.user.Account; |
| 39 | +import com.cloud.utils.Pair; |
| 40 | + |
| 41 | +@APICommand(name = "resetConfiguration", description = "Resets a configuration. The configuration will be set to default value for global setting, and removed from account_details or domain_details for Account/Domain settings", responseObject = ConfigurationResponse.class, |
| 42 | + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0") |
| 43 | +public class ResetCfgCmd extends BaseCmd { |
| 44 | + public static final Logger s_logger = Logger.getLogger(ResetCfgCmd.class.getName()); |
| 45 | + private static final String s_name = "resetconfigurationresponse"; |
| 46 | + |
| 47 | + ///////////////////////////////////////////////////// |
| 48 | + //////////////// API parameters ///////////////////// |
| 49 | + ///////////////////////////////////////////////////// |
| 50 | + |
| 51 | + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the configuration", validations = {ApiArgValidator.NotNullOrEmpty}) |
| 52 | + private String cfgName; |
| 53 | + |
| 54 | + @Parameter(name = ApiConstants.ZONE_ID, |
| 55 | + type = CommandType.UUID, |
| 56 | + entityType = ZoneResponse.class, |
| 57 | + description = "the ID of the Zone to reset the parameter value for corresponding zone") |
| 58 | + private Long zoneId; |
| 59 | + |
| 60 | + @Parameter(name = ApiConstants.CLUSTER_ID, |
| 61 | + type = CommandType.UUID, |
| 62 | + entityType = ClusterResponse.class, |
| 63 | + description = "the ID of the Cluster to reset the parameter value for corresponding cluster") |
| 64 | + private Long clusterId; |
| 65 | + |
| 66 | + @Parameter(name = ApiConstants.STORAGE_ID, |
| 67 | + type = CommandType.UUID, |
| 68 | + entityType = StoragePoolResponse.class, |
| 69 | + description = "the ID of the Storage pool to reset the parameter value for corresponding storage pool") |
| 70 | + private Long storagePoolId; |
| 71 | + |
| 72 | + @Parameter(name = ApiConstants.DOMAIN_ID, |
| 73 | + type = CommandType.UUID, |
| 74 | + entityType = DomainResponse.class, |
| 75 | + description = "the ID of the Domain to reset the parameter value for corresponding domain") |
| 76 | + private Long domainId; |
| 77 | + |
| 78 | + @Parameter(name = ApiConstants.ACCOUNT_ID, |
| 79 | + type = CommandType.UUID, |
| 80 | + entityType = AccountResponse.class, |
| 81 | + description = "the ID of the Account to reset the parameter value for corresponding account") |
| 82 | + private Long accountId; |
| 83 | + |
| 84 | + @Parameter(name = ApiConstants.IMAGE_STORE_ID, |
| 85 | + type = CommandType.UUID, |
| 86 | + entityType = ImageStoreResponse.class, |
| 87 | + description = "the ID of the Image Store to reset the parameter value for corresponding image store") |
| 88 | + private Long imageStoreId; |
| 89 | + |
| 90 | + ///////////////////////////////////////////////////// |
| 91 | + /////////////////// Accessors /////////////////////// |
| 92 | + ///////////////////////////////////////////////////// |
| 93 | + |
| 94 | + public String getCfgName() { |
| 95 | + return cfgName; |
| 96 | + } |
| 97 | + |
| 98 | + public Long getZoneId() { |
| 99 | + return zoneId; |
| 100 | + } |
| 101 | + |
| 102 | + public Long getClusterId() { |
| 103 | + return clusterId; |
| 104 | + } |
| 105 | + |
| 106 | + public Long getStoragepoolId() { |
| 107 | + return storagePoolId; |
| 108 | + } |
| 109 | + |
| 110 | + public Long getDomainId() { |
| 111 | + return domainId; |
| 112 | + } |
| 113 | + |
| 114 | + public Long getAccountId() { |
| 115 | + return accountId; |
| 116 | + } |
| 117 | + |
| 118 | + public Long getImageStoreId() { |
| 119 | + return imageStoreId; |
| 120 | + } |
| 121 | + |
| 122 | + ///////////////////////////////////////////////////// |
| 123 | + /////////////// API Implementation/////////////////// |
| 124 | + ///////////////////////////////////////////////////// |
| 125 | + |
| 126 | + @Override |
| 127 | + public String getCommandName() { |
| 128 | + return s_name; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public long getEntityOwnerId() { |
| 133 | + return Account.ACCOUNT_ID_SYSTEM; |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public void execute() { |
| 138 | + Pair<Configuration, String> cfg = _configService.resetConfiguration(this); |
| 139 | + if (cfg != null) { |
| 140 | + ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg.first()); |
| 141 | + response.setResponseName(getCommandName()); |
| 142 | + if (getZoneId() != null) { |
| 143 | + response.setScope(ConfigKey.Scope.Zone.name()); |
| 144 | + } |
| 145 | + if (getClusterId() != null) { |
| 146 | + response.setScope(ConfigKey.Scope.Cluster.name()); |
| 147 | + } |
| 148 | + if (getStoragepoolId() != null) { |
| 149 | + response.setScope(ConfigKey.Scope.StoragePool.name()); |
| 150 | + } |
| 151 | + if (getDomainId() != null) { |
| 152 | + response.setScope(ConfigKey.Scope.Domain.name()); |
| 153 | + } |
| 154 | + if (getAccountId() != null) { |
| 155 | + response.setScope(ConfigKey.Scope.Account.name()); |
| 156 | + } |
| 157 | + if (getImageStoreId() != null) { |
| 158 | + response.setScope(ConfigKey.Scope.ImageStore.name()); |
| 159 | + } |
| 160 | + response.setValue(cfg.second()); |
| 161 | + this.setResponseObject(response); |
| 162 | + } else { |
| 163 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset config"); |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments