Search in sources :

Example 66 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class MicroserviceVersionRule method printData.

private void printData(MicroserviceVersionRuleData data, int inputVersionCount, int inputInstanceCount) {
    String latestVersion = data.latestVersion == null ? null : data.latestVersion.getVersion().getVersion();
    if (data.getInstances().isEmpty()) {
        LOGGER.info("update instances to be empty caused by version rule, appId={}, microserviceName={}, versionRule={}" + ", latestVersion={}, inputVersionCount={}, inputInstanceCount={}", appId, microserviceName, versionRule.getVersionRule(), latestVersion, inputVersionCount, inputInstanceCount);
        return;
    }
    StringBuilder sb = new StringBuilder();
    StringBuilderUtils.appendLine(sb, "update instances, appId=%s, microserviceName=%s, versionRule=%s" + ", latestVersion=%s, inputVersionCount=%s, inputInstanceCount=%s", appId, microserviceName, versionRule.getVersionRule(), latestVersion, inputVersionCount, inputInstanceCount);
    int idx = 0;
    for (MicroserviceInstance instance : data.getInstances().values()) {
        MicroserviceVersion microserviceVersion = data.versions.get(instance.getServiceId());
        Microservice microservice = microserviceVersion.getMicroservice();
        Framework framework = microservice.getFramework();
        String frameworkName = framework == null ? "unknown" : framework.getName();
        String frameworkVersion = framework == null ? "unknown" : framework.getVersion();
        StringBuilderUtils.appendLine(sb, "  %d.instanceId=%s, status=%s, version=%s, endpoints=%s, environment=%s, framework.name=%s, framework.version=%s", idx, instance.getInstanceId(), instance.getStatus(), microserviceVersion.getVersion(), instance.getEndpoints(), microservice.getEnvironment(), frameworkName, frameworkVersion);
        idx++;
    }
    LOGGER.info(StringBuilderUtils.deleteLast(sb, 1).toString());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Framework(org.apache.servicecomb.registry.api.registry.Framework)

Example 67 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestAuthHandlerBoot method testGenerateRSAKey.

@Test
public void testGenerateRSAKey() {
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    Microservice microservice = new Microservice();
    microservice.setInstance(microserviceInstance);
    AuthHandlerBoot authHandlerBoot = new AuthHandlerBoot();
    BootEvent bootEvent = new BootEvent();
    bootEvent.setEventType(BootListener.EventType.BEFORE_REGISTRY);
    authHandlerBoot.onBootEvent(bootEvent);
    Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPrivateKey());
    Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPublicKey());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) AuthHandlerBoot(org.apache.servicecomb.AuthHandlerBoot) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 68 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestAccessController method testIsValidOfWhiteByServiceName.

@Test
public void testIsValidOfWhiteByServiceName() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    service.setServiceName("trustCustomer");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("nottrustCustomer");
    Assert.assertTrue(!controller.isAllowed(service));
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "*trust");
    service.setServiceName("Customer_trust");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("Customer_trust_not");
    Assert.assertTrue(!controller.isAllowed(service));
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust");
    service.setServiceName("trust");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("Customer_trust");
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 69 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestAccessController method testIsValidOfBlackByProperties.

@Test
public void testIsValidOfBlackByProperties() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "tag");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "test");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    Map<String, String> map = new HashMap<>();
    map.put("tag", "test");
    service.setProperties(map);
    Assert.assertTrue(!controller.isAllowed(service));
    map.put("tag", "testa");
    service.setProperties(map);
    Assert.assertTrue(controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 70 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestAccessController method testIsValidOfBlackAndWhiteByServiceName.

@Test
public void testIsValidOfBlackAndWhiteByServiceName() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*hacker");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    service.setServiceName("trustCustomer");
    Assert.assertTrue(controller.isAllowed(service));
    service.setServiceName("trustCustomerhacker");
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3