All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cloudbees.api.cr.CloudResourceProvider Maven / Gradle / Ivy

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 - 2024 Weber Informatics LLC | Privacy Policy