-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(support-querying): Add support to querying schemas (#51)
* feat(container-is-queryable): send in the api if a container cluster can search or index * feat(support-querying): Add support to querying schemas --------- Co-authored-by: Broknloop <broknloop@gmail.com>
- Loading branch information
1 parent
8f1d10a
commit c713a62
Showing
44 changed files
with
1,333 additions
and
525 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
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 |
---|---|---|
@@ -1,28 +1,42 @@ | ||
package com.vispana.api; | ||
|
||
import com.vispana.api.model.VispanaRoot; | ||
import com.vispana.client.vespa.VespaClient; | ||
import com.vispana.vespa.query.VespaQueryClient; | ||
import com.vispana.vespa.state.VespaStateClient; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class MainController { | ||
|
||
private final VespaClient vespaClient; | ||
private final VespaStateClient vespaStateClient; | ||
private final VespaQueryClient vespaQueryClient; | ||
|
||
@Autowired | ||
public MainController(VespaClient vespaClient) { | ||
this.vespaClient = vespaClient; | ||
public MainController(VespaStateClient vespaStateClient, VespaQueryClient vespaQueryClient) { | ||
this.vespaStateClient = vespaStateClient; | ||
this.vespaQueryClient = vespaQueryClient; | ||
} | ||
|
||
@GetMapping( | ||
value = "/api/overview", | ||
produces = {"application/json"}) | ||
@ResponseBody | ||
public VispanaRoot root(@RequestParam(name = "config_host") String configHost) { | ||
return vespaClient.vespaState(configHost); | ||
return vespaStateClient.vespaState(configHost); | ||
} | ||
|
||
@PostMapping( | ||
value = "/api/query", | ||
produces = {"application/json"}) | ||
@ResponseBody | ||
public String query( | ||
@RequestParam(name = "container_host") String containerHost, @RequestBody String query) { | ||
return vespaQueryClient.query(containerHost, query); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
src/main/java/com/vispana/client/vespa/assemblers/AppPackageAssembler.java
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
src/main/java/com/vispana/client/vespa/assemblers/ContainerAssembler.java
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/vispana/vespa/query/VespaQueryClient.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,44 @@ | ||
package com.vispana.vespa.query; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
|
||
import java.nio.channels.UnresolvedAddressException; | ||
import org.apache.commons.lang.exception.ExceptionUtils; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.ResourceAccessException; | ||
import org.springframework.web.client.RestClient; | ||
|
||
@Component | ||
public class VespaQueryClient { | ||
|
||
private static final RestClient restClient = RestClient.create(); | ||
|
||
public String query(String vespaContainerHost, String query) { | ||
try { | ||
return restClient | ||
.post() | ||
.uri(vespaContainerHost + "/search/") | ||
.contentType(APPLICATION_JSON) | ||
.body(query) | ||
.retrieve() | ||
.body(String.class); | ||
} catch (ResourceAccessException e) { | ||
var exception = ExceptionUtils.getRootCause(e); | ||
if (exception instanceof UnresolvedAddressException) { | ||
var message = | ||
"Failed to reach to Vespa container for host: '" | ||
+ vespaContainerHost | ||
+ "'.\n" | ||
+ "Vespa clusters may have internal access to this address, please check if " | ||
+ "the host is reachable from Vispana. If not, you may configure a routing " | ||
+ "address in Vispana's configuration pointing to a reachable address (e.g" | ||
+ "., a load balancer or a k8s service)."; | ||
throw new RuntimeException(message); | ||
} else { | ||
throw e; | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException("Error querying Vespa." + e.getMessage(), e); | ||
} | ||
} | ||
} |
19 changes: 9 additions & 10 deletions
19
...pana/client/vespa/DefaultVespaClient.java → ...vispana/vespa/state/VespaStateClient.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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/vispana/vespa/state/assemblers/AppPackageAssembler.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,19 @@ | ||
package com.vispana.vespa.state.assemblers; | ||
|
||
import static com.vispana.vespa.state.helpers.Request.requestGet; | ||
import static com.vispana.vespa.state.helpers.Request.requestGetWithDefaultValue; | ||
|
||
import com.vispana.api.model.apppackage.ApplicationPackage; | ||
import com.vispana.client.vespa.model.ApplicationSchema; | ||
|
||
public class AppPackageAssembler { | ||
|
||
public static ApplicationPackage assemble(String appUrl) { | ||
var appSchema = requestGet(appUrl, ApplicationSchema.class); | ||
var hostContent = requestGetWithDefaultValue(appUrl + "/content/hosts.xml", String.class, ""); | ||
var servicesContent = requestGet(appUrl + "/content/services.xml", String.class); | ||
|
||
return new ApplicationPackage( | ||
appSchema.getGeneration().toString(), servicesContent, hostContent); | ||
} | ||
} |
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
Oops, something went wrong.