/** * Create an instance of {@link Api } * */ public Api createApi() { return new Api(); }
@Override public V3API adapt(Api from) { V3API to = new V3API(); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); } // Remove the links for "rels" that are new in version 4 of the API: if (from.isSetLinks()) { List<Link> links = from.getLinks().stream() .filter(link -> !RELS_TO_REMOVE.contains(link.getRel())) .collect(toList()); to.getLinks().addAll(adaptOut(links)); } // In version 4 of the API the "capabilities" resource was removed, but it still exists in version 3, so we // need to explicitly add a the link: to.getLinks().add(0, makeCapabilitiesLink()); if (from.isSetSpecialObjects()) { to.setSpecialObjects(adaptOut(from.getSpecialObjects())); } if (from.isSetProductInfo()) { to.setProductInfo(adaptOut(from.getProductInfo())); } if (from.isSetSummary()) { to.setSummary(adaptOut(from.getSummary())); } if (from.isSetTime()) { to.setTime(from.getTime()); } return to; }
protected void verifyApiGlusterOnly(Api api) { assertNotNull(api); assertNotNull(api.getTime()); assertNotNull(api.getLinks()); assertEquals(relationshipsGlusterOnly.length, api.getLinks().size()); for (int i = 0; i < relationshipsGlusterOnly.length; i++) { Link l = api.getLinks().get(i); assertNotNull(l); assertEquals(relationshipsGlusterOnly[i], l.getRel()); assertEquals(hrefsGlusterOnly[i], l.getHref()); } assertNotNull(api.getSpecialObjects()); assertContainsRootTag(api.getSpecialObjects()); assertNotNull(api.getProductInfo()); assertNotNull(api.getProductInfo().getVersion()); assertEquals(MAJOR, api.getProductInfo().getVersion().getMajor().intValue()); assertEquals(MINOR, api.getProductInfo().getVersion().getMinor().intValue()); assertEquals(BUILD, api.getProductInfo().getVersion().getBuild().intValue()); assertEquals(REVISION, api.getProductInfo().getVersion().getRevision().intValue()); assertNotNull(api.getSummary()); assertEquals(TOTAL_HOSTS, api.getSummary().getHosts().getTotal().intValue()); assertEquals(ACTIVE_HOSTS, api.getSummary().getHosts().getActive().intValue()); assertEquals(TOTAL_USERS, api.getSummary().getUsers().getTotal().intValue()); assertEquals(ACTIVE_USERS, api.getSummary().getUsers().getActive().intValue()); }
private Api getGlusterApi() { Api api = new Api(); api.setTime(DateMapper.map(new Date(), null)); for (DetailedLink detailedLink : getGlusterLinks()) { // add thin link api.getLinks().add(LinkCreator.createLink(detailedLink.getHref(), detailedLink.getRel())); // when required - add extra link for search if (detailedLink.isSetLinkCapabilities() && detailedLink.getLinkCapabilities().isSetSearchable() && detailedLink.getLinkCapabilities().isSearchable()) { api.getLinks().add(LinkCreator.createLink(detailedLink.getHref(), detailedLink.getRel(), detailedLink.getRequest().getUrl().getParametersSets())); } // add special links SpecialObjects specialObjects = new SpecialObjects(); specialObjects.setRootTag(createRootTag()); api.setSpecialObjects(specialObjects); } return api; }
protected void verifyApi(Api api) { assertNotNull(api); assertNotNull(api.getTime()); assertNotNull(api.getLinks()); assertEquals(relationships.length, api.getLinks().size()); for (int i = 0; i < relationships.length; i++) { Link l = api.getLinks().get(i); assertNotNull(l); assertEquals(relationships[i], l.getRel()); assertNotNull(api.getSpecialObjects()); assertContainsRootTag(api.getSpecialObjects()); assertContainsBlankTemplate(api.getSpecialObjects()); assertNotNull(api.getProductInfo()); assertNotNull(api.getProductInfo().getVersion()); assertNotNull(api.getProductInfo().getVersion().getFullVersion()); assertEquals(MAJOR, api.getProductInfo().getVersion().getMajor().intValue()); assertEquals(MINOR, api.getProductInfo().getVersion().getMinor().intValue()); assertEquals(BUILD, api.getProductInfo().getVersion().getBuild().intValue()); assertEquals(REVISION, api.getProductInfo().getVersion().getRevision().intValue()); assertNotNull(api.getSummary()); assertEquals(TOTAL_VMS, api.getSummary().getVms().getTotal().intValue()); assertEquals(ACTIVE_VMS, api.getSummary().getVms().getActive().intValue()); assertEquals(TOTAL_HOSTS, api.getSummary().getHosts().getTotal().intValue()); assertEquals(ACTIVE_HOSTS, api.getSummary().getHosts().getActive().intValue()); assertEquals(TOTAL_USERS, api.getSummary().getUsers().getTotal().intValue()); assertEquals(ACTIVE_USERS, api.getSummary().getUsers().getActive().intValue()); assertEquals(TOTAL_STORAGE_DOMAINS, api.getSummary().getStorageDomains().getTotal().intValue());
private Api getApi() { Api api = new Api(); api.setTime(DateMapper.map(new Date(), null)); for (DetailedLink detailedLink : getLinks()) { //add thin link api.getLinks().add(LinkCreator.createLink(detailedLink.getHref(), detailedLink.getRel())); //when required - add extra link for search if (detailedLink.isSetLinkCapabilities() && detailedLink.getLinkCapabilities().isSetSearchable() && detailedLink.getLinkCapabilities().isSearchable()) { api.getLinks().add(LinkCreator.createLink(detailedLink.getHref(), detailedLink.getRel(), detailedLink.getRequest().getUrl().getParametersSets())); } //add special links SpecialObjects specialObjects = new SpecialObjects(); specialObjects.setBlankTemplate(createBlankTemplate()); specialObjects.setRootTag(createRootTag()); api.setSpecialObjects(specialObjects); } return api; }