use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImpl method getSchemas.
@Override
public Holder<List<GetSchemaResponse>> getSchemas(String microserviceId) {
Microservice microservice = microserviceIdMap.get(microserviceId);
if (microservice == null) {
throw new IllegalArgumentException("Invalid serviceId, serviceId=" + microserviceId);
}
List<GetSchemaResponse> schemas = new ArrayList<>();
microservice.getSchemaMap().forEach((key, val) -> {
GetSchemaResponse schema = new GetSchemaResponse();
schema.setSchema(val);
schema.setSchemaId(key);
schema.setSummary(Hashing.sha256().newHasher().putString(val, Charsets.UTF_8).hash().toString());
schemas.add(schema);
});
Holder<List<GetSchemaResponse>> resultHolder = new Holder<>();
resultHolder.setStatusCode(Status.OK.getStatusCode()).setValue(schemas);
return resultHolder;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImpl method registerSchema.
@Override
public boolean registerSchema(String microserviceId, String schemaId, String schemaContent) {
Microservice microservice = microserviceIdMap.get(microserviceId);
if (microservice == null) {
throw new IllegalArgumentException("Invalid serviceId, serviceId=" + microserviceId);
}
microservice.getSchemaMap().put(schemaId, schemaContent);
return true;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImpl method getMicroserviceId.
@Override
public String getMicroserviceId(String appId, String microserviceName, String strVersionRule, String environment) {
VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
Microservice latest = findLatest(appId, microserviceName, versionRule);
return latest != null ? latest.getServiceId() : null;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImpl method findLatest.
protected Microservice findLatest(String appId, String serviceName, VersionRule versionRule) {
Version latestVersion = null;
Microservice latest = null;
for (Entry<String, Microservice> entry : microserviceIdMap.entrySet()) {
Microservice microservice = entry.getValue();
if (!isSameMicroservice(microservice, appId, serviceName)) {
continue;
}
Version version = VersionUtils.getOrCreate(microservice.getVersion());
if (!versionRule.isAccept(version)) {
continue;
}
if (latestVersion == null || version.compareTo(latestVersion) > 0) {
latestVersion = version;
latest = microservice;
}
}
return latest;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestEnvAdapterManager method testProcessMicroservice.
@Test
public void testProcessMicroservice() {
Microservice microservice = new Microservice();
manager.processMicroserviceWithAdapters(microservice);
assertEquals("order=0", microservice.getProperties().get("cas_env_one"));
assertEquals("order=0", microservice.getProperties().get("cas_env_two"));
assertNull(microservice.getProperties().get("default-env-adapter"));
}
Aggregations