
com.cloudbees.api.cr.CloudResourceProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudbees-api-client Show documentation
Show all versions of cloudbees-api-client Show documentation
The CloudBees API Client library for Java
package com.cloudbees.api.cr;
import org.codehaus.jackson.JsonNode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Lists up {@link CloudResource}s that belong to it.
*
* @author Kohsuke Kawaguchi
*/
@CloudResourceType("https://types.cloudbees.com/resource/provider")
public class CloudResourceProvider extends CloudResourceFacet implements Iterable {
public CloudResourceProvider(CloudResource owner) {
super(owner);
}
/**
* Lists up all the cloud resources.
*/
public Iterator iterator() {
try {
JsonNode res = getOwner().retrieve().get("resources");
if (res==null || !res.isArray())
throw new IllegalStateException("Expected a JSON array but "+getOwner()+" gave us "+res);
ReferencedResource[] dto = CloudResource.MAPPER.readValue(res, ReferencedResource[].class);
List r = new ArrayList(dto.length);
for (ReferencedResource rr : dto) {
r.add(rr.toCloudResource(getOwner()));
}
return r.iterator();
} catch (IOException e) {
throw new Error(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy