Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PUBDEV-4280] Create capabilities rest endpoints
(cherry picked from commit af4299b)
- Loading branch information
1 parent
4702649
commit c8b59a8
Showing
6 changed files
with
121 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package water.api; | ||
|
||
import water.AbstractH2OExtension; | ||
import water.H2O; | ||
import water.api.schemas3.CapabilitiesV3; | ||
import water.api.schemas3.CapabilityEntryV3; | ||
|
||
import java.util.ArrayList; | ||
|
||
|
||
public class CapabilitiesHandler extends Handler{ | ||
|
||
private ArrayList<CapabilityEntryV3> getCoreExtensionEntries(){ | ||
ArrayList<CapabilityEntryV3> entries = new ArrayList<>(); | ||
for(AbstractH2OExtension ext: H2O.getCoreExtensions()){ | ||
entries.add(new CapabilityEntryV3(ext.getExtensionName())); | ||
} | ||
return entries; | ||
} | ||
|
||
private ArrayList<CapabilityEntryV3> getRestAPIExtensionEntries(){ | ||
ArrayList<CapabilityEntryV3> entries = new ArrayList<>(); | ||
for(RestApiExtension ext: H2O.getRestApiExtensions()){ | ||
entries.add(new CapabilityEntryV3(ext.getName())); | ||
} | ||
return entries; | ||
} | ||
|
||
|
||
@SuppressWarnings("unused") // called through reflection by RequestServer | ||
public CapabilitiesV3 listAll(int version, CapabilitiesV3 s) { | ||
ArrayList<CapabilityEntryV3> entries = new ArrayList<>(); | ||
entries.addAll(getCoreExtensionEntries()); | ||
entries.addAll(getRestAPIExtensionEntries()); | ||
s.capabilities = entries.toArray(new CapabilityEntryV3[entries.size()]); | ||
return s; | ||
} | ||
|
||
@SuppressWarnings("unused") // called through reflection by RequestServer | ||
public CapabilitiesV3 listCore(int version, CapabilitiesV3 s) { | ||
ArrayList<CapabilityEntryV3> entries = new ArrayList<>(); | ||
entries.addAll(getCoreExtensionEntries()); | ||
s.capabilities = entries.toArray(new CapabilityEntryV3[entries.size()]); | ||
return s; | ||
} | ||
|
||
@SuppressWarnings("unused") // called through reflection by RequestServer | ||
public CapabilitiesV3 listRest(int version, CapabilitiesV3 s) { | ||
ArrayList<CapabilityEntryV3> entries = new ArrayList<>(); | ||
entries.addAll(getRestAPIExtensionEntries()); | ||
s.capabilities = entries.toArray(new CapabilityEntryV3[entries.size()]); | ||
return s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
h2o-core/src/main/java/water/api/schemas3/CapabilitiesV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package water.api.schemas3; | ||
|
||
|
||
import water.Iced; | ||
import water.api.API; | ||
|
||
public class CapabilitiesV3 extends RequestSchemaV3<Iced, CapabilitiesV3> { | ||
|
||
@API(help = "List of H2O capabilities", direction = API.Direction.OUTPUT) | ||
public CapabilityEntryV3[] capabilities; | ||
} |
14 changes: 14 additions & 0 deletions
14
h2o-core/src/main/java/water/api/schemas3/CapabilityEntryV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package water.api.schemas3; | ||
|
||
import water.Iced; | ||
import water.api.API; | ||
|
||
public class CapabilityEntryV3 extends SchemaV3<Iced, CapabilityEntryV3> { | ||
@API(help = "Extension name", direction = API.Direction.OUTPUT) | ||
public String name; | ||
|
||
public CapabilityEntryV3() {} | ||
public CapabilityEntryV3(String name) { | ||
this.name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters