public static BlockStoragePolicyProto convert(BlockStoragePolicy policy) { BlockStoragePolicyProto.Builder builder = BlockStoragePolicyProto .newBuilder().setPolicyId(policy.getId()).setName(policy.getName()); // creation storage types StorageTypesProto creationProto = convert(policy.getStorageTypes()); Preconditions.checkArgument(creationProto != null); builder.setCreationPolicy(creationProto); // creation fallback StorageTypesProto creationFallbackProto = convert( policy.getCreationFallbacks()); if (creationFallbackProto != null) { builder.setCreationFallbackPolicy(creationFallbackProto); } // replication fallback StorageTypesProto replicationFallbackProto = convert( policy.getReplicationFallbacks()); if (replicationFallbackProto != null) { builder.setReplicationFallbackPolicy(replicationFallbackProto); } return builder.build(); }
public static BlockStoragePolicy[] convertStoragePolicies( List<BlockStoragePolicyProto> policyProtos) { if (policyProtos == null || policyProtos.size() == 0) { return new BlockStoragePolicy[0]; } BlockStoragePolicy[] policies = new BlockStoragePolicy[policyProtos.size()]; int i = 0; for (BlockStoragePolicyProto proto : policyProtos) { policies[i++] = convert(proto); } return policies; }
public static BlockStoragePolicy convert(BlockStoragePolicyProto proto) { List<StorageTypeProto> cList = proto.getCreationPolicy() .getStorageTypesList(); StorageType[] creationTypes = convertStorageTypes(cList, cList.size()); List<StorageTypeProto> cfList = proto.hasCreationFallbackPolicy() ? proto .getCreationFallbackPolicy().getStorageTypesList() : null; StorageType[] creationFallbackTypes = cfList == null ? StorageType .EMPTY_ARRAY : convertStorageTypes(cfList, cfList.size()); List<StorageTypeProto> rfList = proto.hasReplicationFallbackPolicy() ? proto.getReplicationFallbackPolicy().getStorageTypesList() : null; StorageType[] replicationFallbackTypes = rfList == null ? StorageType .EMPTY_ARRAY : convertStorageTypes(rfList, rfList.size()); return new BlockStoragePolicy((byte) proto.getPolicyId(), proto.getName(), creationTypes, creationFallbackTypes, replicationFallbackTypes); }
@Override public GetStoragePolicyResponseProto getStoragePolicy( RpcController controller, GetStoragePolicyRequestProto request) throws ServiceException { try { BlockStoragePolicyProto policy = PBHelperClient.convert(server .getStoragePolicy(request.getPath())); return GetStoragePolicyResponseProto.newBuilder() .setStoragePolicy(policy).build(); } catch (IOException e) { throw new ServiceException(e); } }