本文整理了Java中org.apache.cloudstack.api.Parameter
类的一些代码示例,展示了Parameter
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parameter
类的具体详情如下:
包路径:org.apache.cloudstack.api.Parameter
类名称:Parameter
暂无
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.SNAPSHOT_POLICY_ID, type = CommandType.LONG, description = "lists recurring snapshots by snapshot policy ID")
private Long snapshotPolicyId;
@Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.LONG, required = true, description = "list recurring snapshots by volume ID")
private Long volumeId;
代码示例来源:origin: apache/cloudstack
for (Field f : fields) {
Parameter parameterAnnotation = f.getAnnotation(Parameter.class);
if (parameterAnnotation != null && parameterAnnotation.expose() && parameterAnnotation.includeInApiDoc()) {
Argument reqArg = new Argument(parameterAnnotation.name());
reqArg.setRequired(parameterAnnotation.required());
if (!parameterAnnotation.description().isEmpty()) {
reqArg.setDescription(parameterAnnotation.description());
if (parameterAnnotation.type() == BaseCmd.CommandType.LIST || parameterAnnotation.type() == BaseCmd.CommandType.MAP) {
reqArg.setType(parameterAnnotation.type().toString().toLowerCase());
reqArg.setDataType(parameterAnnotation.type().toString().toLowerCase());
if (!parameterAnnotation.since().isEmpty()) {
reqArg.setSinceVersion(parameterAnnotation.since());
if (parameterAnnotation.name().equals("id")) {
id = reqArg;
} else {
代码示例来源:origin: apache/cloudstack
private void validateField(final Object paramObj, final Parameter annotation) throws ServerApiException {
if (annotation == null) {
return;
}
final String argName = annotation.name();
for (final ApiArgValidator validator : annotation.validations()) {
if (validator == null) {
continue;
}
switch (validator) {
case NotNullOrEmpty:
switch (annotation.type()) {
case UUID:
case STRING:
validateNonEmptyString(paramObj, argName);
break;
}
break;
case PositiveNumber:
switch (annotation.type()) {
case SHORT:
case INTEGER:
case LONG:
validateNaturalNumber(paramObj, argName);
break;
}
break;
}
}
}
代码示例来源:origin: apache/cloudstack
private ApiDiscoveryResponse getCmdRequestMap(Class<?> cmdClass, APICommand apiCmdAnnotation) {
String apiName = apiCmdAnnotation.name();
ApiDiscoveryResponse response = new ApiDiscoveryResponse();
response.setName(apiName);
response.setDescription(apiCmdAnnotation.description());
if (!apiCmdAnnotation.since().isEmpty()) {
response.setSince(apiCmdAnnotation.since());
}
Set<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass, new Class<?>[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass, new Class<?>[] {BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
response.setAsync(isAsync);
for (Field field : fields) {
Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
if (parameterAnnotation != null && parameterAnnotation.expose() && parameterAnnotation.includeInApiDoc()) {
ApiParameterResponse paramResponse = new ApiParameterResponse();
paramResponse.setName(parameterAnnotation.name());
paramResponse.setDescription(parameterAnnotation.description());
paramResponse.setType(parameterAnnotation.type().toString().toLowerCase());
paramResponse.setLength(parameterAnnotation.length());
paramResponse.setRequired(parameterAnnotation.required());
if (!parameterAnnotation.since().isEmpty()) {
paramResponse.setSince(parameterAnnotation.since());
}
paramResponse.setRelated(parameterAnnotation.entityType()[0].getName());
response.addParam(paramResponse);
}
}
return response;
}
代码示例来源:origin: apache/cloudstack
final Object paramObj = params.get(parameterAnnotation.name());
if (paramObj == null) {
if (parameterAnnotation.required()) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) +
" due to missing parameter " + parameterAnnotation.name());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " +
parameterAnnotation.name());
parameterAnnotation.name());
} catch (final ParseException parseEx) {
if (s_logger.isDebugEnabled()) {
final CommandType fieldType = parameterAnnotation.type();
if (parameterAnnotation.entityType() != null && parameterAnnotation.entityType().length > 0
&& parameterAnnotation.entityType()[0].getAnnotation(EntityReference.class) != null) {
final Class<?>[] entityList = parameterAnnotation.entityType()[0].getAnnotation(EntityReference.class).value();
final CommandType listType = parameterAnnotation.collectionType();
switch (listType) {
case LONG:
代码示例来源:origin: apache/cloudstack
final boolean isPre3x = annotation.since().isEmpty();
final Class<?>[] entities = annotation.entityType()[0].getAnnotation(EntityReference.class).value();
CallContext.current().putContextParameter(entity, internalId);
validateNaturalNumber(internalId, annotation.name());
return internalId;
if (s_logger.isDebugEnabled())
s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid +
" due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
validateNaturalNumber(internalId, annotation.name());
return internalId;
代码示例来源:origin: apache/cloudstack
for (Field field : fields) {
Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
if ((parameterAnnotation == null) || !parameterAnnotation.expose()) {
continue;
Object paramObj = parameterMap.get(parameterAnnotation.name());
if (paramObj != null) {
if (!parameterAnnotation.acceptedOnAdminPort()) {
throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, "Parameter " + parameterAnnotation.name() + " can't be passed through the API integration port");
代码示例来源:origin: apache/cloudstack
final RoleType[] allowedRoles = parameterAnnotation.authorized();
boolean roleIsAllowed = true;
if (allowedRoles.length > 0) {
validFields.add(field);
} else {
s_logger.debug("Ignoring paremeter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in");
代码示例来源:origin: apache/cloudstack
protected List<String> getParamNamesForCommand(final BaseCmd cmd) {
final List<String> paramNames = new ArrayList<String>();
// The expected param names are all the specific for the current command class ...
for (final Field field : cmd.getParamFields()) {
final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
paramNames.add(parameterAnnotation.name());
}
// ... plus the default ones
paramNames.addAll(defaultParamNames);
return paramNames;
}
}
代码示例来源:origin: apache/cloudstack
protected List<Field> getAllFieldsForClass(final Class<?> clazz) {
List<Field> filteredFields = fieldsForCmdClass.get(clazz);
// If list of fields was not cached yet
if (filteredFields == null) {
final List<Field> allFields = ReflectUtil.getAllFieldsForClass(this.getClass(), BaseCmd.class);
filteredFields = new ArrayList<Field>();
for (final Field field : allFields) {
final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
if ((parameterAnnotation != null) && parameterAnnotation.expose()) {
filteredFields.add(field);
}
}
// Cache the prepared list for future use
fieldsForCmdClass.put(clazz, filteredFields);
}
return filteredFields;
}
代码示例来源:origin: apache/cloudstack
public static void set(BaseCmd cmd, String fieldName, Object value)
throws IllegalArgumentException, IllegalAccessException {
for (Field field : cmd.getClass().getDeclaredFields()) {
Parameter parameter = field.getAnnotation(Parameter.class);
if (parameter != null && fieldName.equals(parameter.name())) {
field.setAccessible(true);
field.set(cmd, value);
}
}
}
代码示例来源:origin: apache/cloudstack
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.UUID, entityType=HostResponse.class,
description="the host ID")
private Long hostId;
@Parameter(name=ApiConstants.POD_ID, type=CommandType.UUID, entityType=PodResponse.class,
description="the pod ID")
private Long podId;
@Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.UUID, entityType=StoragePoolResponse.class,
description="the storage ID where vm's volumes belong to")
private Long storageId;
代码示例来源:origin: apache/cloudstack
private static final String s_name = "listtagsresponse";
@Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, description = "list by resource type")
private String resourceType;
@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, description = "list by resource id")
private String resourceId;
@Parameter(name = ApiConstants.KEY, type = CommandType.STRING, description = "list by key")
private String key;
@Parameter(name = ApiConstants.VALUE, type = CommandType.STRING, description = "list by value")
private String value;
@Parameter(name = ApiConstants.CUSTOMER, type = CommandType.STRING, description = "list by customer name")
private String customer;
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.ACCOUNT_TYPE,
type = CommandType.LONG,
description = "List users by account type. Valid types include admin, domain-admin, read-only-admin, or user.")
private Long accountType;
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = UserResponse.class, description = "List user by ID.")
private Long id;
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "List users by state of the user account.")
private String state;
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "List user by the username")
private String username;
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.ID, type = CommandType.STRING, description = "the id of the annotation")
private String uuid;
@Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, description = "the entity type")
private String entityType;
@Parameter(name = ApiConstants.ENTITY_ID, type = CommandType.STRING, description = "the id of the entity for which to show annotations")
private String entityUuid;
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.ANNOTATION, type = CommandType.STRING, description = "the annotation text")
private String annotation;
@Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, description = "the entity type (only HOST is allowed atm)")
private String entityType;
@Parameter(name = ApiConstants.ENTITY_ID, type = CommandType.STRING, description = "the id of the entity to annotate")
private String entityUuid;
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, required = true, description = "ID of the project")
private Long projectId;
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "list accounts of the project by account name")
private String accountName;
@Parameter(name = ApiConstants.ROLE, type = CommandType.STRING, description = "list accounts of the project by role")
private String role;
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.SECURITY_GROUP_NAME, type = CommandType.STRING, description = "lists security groups by name")
private String securityGroupName;
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
type = CommandType.UUID,
description = "lists security groups by virtual machine id",
private Long virtualMachineId;
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "list the security group by the id provided", entityType = SecurityGroupResponse.class)
private Long id;
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = StaticRouteResponse.class, description = "list static route by id")
private Long id;
@Parameter(name = ApiConstants.VPC_ID, type = CommandType.UUID, entityType = VpcResponse.class, description = "list static routes by vpc id")
private Long vpcId;
@Parameter(name = ApiConstants.GATEWAY_ID, type = CommandType.UUID, entityType = PrivateGatewayResponse.class, description = "list static routes by gateway id")
private Long gatewayId;
代码示例来源:origin: apache/cloudstack
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GuestOSResponse.class, description = "list by Os type Id")
private Long id;
@Parameter(name = ApiConstants.OS_CATEGORY_ID, type = CommandType.UUID, entityType = GuestOSCategoryResponse.class, description = "list by Os Category id")
private Long osCategoryId;
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "list os by description", since = "3.0.1")
private String description;
内容来源于网络,如有侵权,请联系作者删除!