@Test
  public void promoteScopeToTenantForbiddenTest() throws Exception {
    ApplicationDto application = createApplication(tenantAdminDto);
    ;
    this.loginTenantAdmin(tenantAdminUser);

    CTLSchemaDto saved =
        this.createCTLSchema(
            this.ctlRandomFieldType(),
            CTL_DEFAULT_NAMESPACE,
            1,
            tenantAdminDto.getTenantId(),
            null,
            null,
            null);
    final CTLSchemaMetaInfoDto metaInfo3 = saved.getMetaInfo();

    Assert.assertNull(metaInfo3.getApplicationId());
    metaInfo3.setApplicationId(application.getId());

    this.checkForbidden(
        new TestRestCall() {
          @Override
          public void executeRestCall() throws Exception {
            client.promoteScopeToTenant(metaInfo3.getApplicationId(), metaInfo3.getFqn());
          }
        });
  }
Esempio n. 2
0
  @Test
  public void updateProfileServiceTest() throws IOException {
    byte[] profile = baseAvroConverter.encode(ENDPOINT_PROFILE);
    RegisterProfileRequest request =
        new RegisterProfileRequest(
            application.getApplicationToken(), ENDPOINT_KEY, sdkToken, profile);

    EndpointProfileDto oldDto = profileService.registerProfile(request);

    Assert.assertEquals(
        baseAvroConverter.encodeToJson(ENDPOINT_PROFILE),
        oldDto.getClientProfileBody().replaceAll(" ", ""));

    byte[] newProfile = newAvroConverter.encode(NEW_ENDPOINT_PROFILE);
    UpdateProfileRequest updateRequest =
        new UpdateProfileRequest(
            application.getApplicationToken(),
            EndpointObjectHash.fromSha1(ENDPOINT_KEY),
            null,
            newProfile,
            newSdkToken);
    EndpointProfileDto newDto = profileService.updateProfile(updateRequest);

    Assert.assertNotNull(newDto);
    Assert.assertNotNull(newDto.getId());
    Assert.assertEquals(oldDto.getId(), newDto.getId());
    Assert.assertEquals(
        newAvroConverter.encodeToJson(NEW_ENDPOINT_PROFILE),
        newDto.getClientProfileBody().replaceAll(" ", ""));
    Assert.assertTrue(
        Arrays.equals(EndpointObjectHash.fromSha1(newProfile).getData(), newDto.getProfileHash()));
  }
  @Test
  public void promoteScopeToTenantNotFoundTest() throws Exception {
    ApplicationDto application = createApplication(tenantAdminDto);
    this.loginTenantDeveloper(tenantDeveloperUser);
    CTLSchemaDto saved =
        this.createCTLSchema(
            this.ctlRandomFieldType(),
            CTL_DEFAULT_NAMESPACE,
            1,
            tenantDeveloperDto.getTenantId(),
            null,
            null,
            null);
    final CTLSchemaMetaInfoDto metaInfo2 = saved.getMetaInfo();

    Assert.assertNull(metaInfo2.getApplicationId());
    metaInfo2.setApplicationId(application.getId());

    this.checkRestErrorStatusCode(
        new TestRestCall() {
          @Override
          public void executeRestCall() throws Exception {
            client.promoteScopeToTenant(metaInfo2.getApplicationId(), metaInfo2.getFqn());
          }
        },
        HttpStatus.NOT_FOUND);
  }
 private ApplicationDto getApplicationWithName(List<ApplicationDto> applications, String name) {
   for (ApplicationDto application : applications) {
     if (name.equalsIgnoreCase(application.getName())) {
       return application;
     }
   }
   return null;
 }
Esempio n. 5
0
  @Test
  public void testDeltaServiceFirstRequest() throws Exception {
    GetDeltaRequest request = new GetDeltaRequest(application.getApplicationToken());
    request.setEndpointProfile(endpointProfile);
    GetDeltaResponse response = deltaService.getDelta(request);

    assertNotNull(response);
    assertEquals(GetDeltaResponse.GetDeltaResponseType.CONF_RESYNC, response.getResponseType());
    assertNotNull(response.getDelta());
    endpointConfigurationBytes = response.getDelta().getData();
    assertNotNull(endpointConfigurationBytes);
  }
  @Test
  public void promoteScopeToTenantWithDependenciesInAppScopeTest() throws Exception {
    ApplicationDto application = createApplication(tenantAdminDto);
    loginTenantDeveloper(tenantDeveloperUser);

    CTLSchemaDto dep =
        createCTLSchema(
            ctlRandomFieldType(),
            CTL_DEFAULT_NAMESPACE,
            1,
            tenantDeveloperDto.getTenantId(),
            application.getApplicationToken(),
            null,
            null);
    String fqn = dep.getMetaInfo().getFqn();
    int version = dep.getVersion();
    Map<String, String> fields = ImmutableMap.of("test", fqn);
    Set<FqnVersion> deps = ImmutableSet.of(new FqnVersion(fqn, version));
    CTLSchemaDto schema =
        createCTLSchema(
            ctlRandomFieldType(),
            CTL_DEFAULT_NAMESPACE,
            1,
            tenantDeveloperDto.getTenantId(),
            application.getApplicationToken(),
            deps,
            fields);

    final CTLSchemaMetaInfoDto metaInfo = schema.getMetaInfo();

    checkRestErrorStatusCode(
        new TestRestCall() {
          @Override
          public void executeRestCall() throws Exception {
            client.promoteScopeToTenant(metaInfo.getApplicationId(), metaInfo.getFqn());
          }
        },
        HttpStatus.CONFLICT);
  }
Esempio n. 7
0
  @Test
  public void testDeltaServiceHashMismatch() throws Exception {
    GetDeltaRequest request =
        new GetDeltaRequest(
            application.getApplicationToken(), EndpointObjectHash.fromBytes(new byte[] {1, 2, 3}));
    request.setEndpointProfile(endpointProfile);
    GetDeltaResponse response = deltaService.getDelta(request);

    assertNotNull(response);
    assertEquals(GetDeltaResponse.GetDeltaResponseType.CONF_RESYNC, response.getResponseType());
    assertNotNull(response.getDelta());
    endpointConfigurationBytes = response.getDelta().getData();
    assertNotNull(endpointConfigurationBytes);
  }
Esempio n. 8
0
 @Test
 public void testDeltaServiceNoHistoryDelta() throws Exception {
   GetDeltaRequest request =
       new GetDeltaRequest(
           application.getApplicationToken(),
           EndpointObjectHash.fromSha1(endpointConfiguration.getConfiguration()),
           true);
   request.setEndpointProfile(endpointProfile);
   GetDeltaResponse response = deltaService.getDelta(request);
   assertNotNull(response);
   assertEquals(GetDeltaResponse.GetDeltaResponseType.NO_DELTA, response.getResponseType());
   assertNull(response.getDelta());
   assertNull(response.getConfSchema());
 }
  @Test
  public void updateCTLSchemaScopeTest() throws Exception {
    ApplicationDto application = createApplication(tenantAdminDto);
    this.loginTenantDeveloper(tenantDeveloperUser);

    CTLSchemaDto saved =
        this.createCTLSchema(
            this.ctlRandomFieldType(),
            CTL_DEFAULT_NAMESPACE,
            1,
            tenantDeveloperDto.getTenantId(),
            application.getApplicationToken(),
            null,
            null);
    CTLSchemaMetaInfoDto metaInfo = saved.getMetaInfo();
    CTLSchemaMetaInfoDto updatedMetaInfo =
        client.promoteScopeToTenant(metaInfo.getApplicationId(), metaInfo.getFqn());

    Assert.assertNull(updatedMetaInfo.getApplicationId());
    Assert.assertNotNull(updatedMetaInfo.getTenantId());
    Assert.assertEquals(tenantDeveloperDto.getTenantId(), updatedMetaInfo.getTenantId());
    Assert.assertEquals(CTLSchemaScopeDto.TENANT, updatedMetaInfo.getScope());
  }
 /**
  * Retrieves a CTL schema by its id.
  *
  * @throws Exception
  */
 @Test
 public void downloadCtlSchemaTest() throws Exception {
   ApplicationDto application = createApplication(tenantAdminDto);
   this.loginTenantDeveloper(tenantDeveloperUser);
   String name = this.ctlRandomFieldType();
   CTLSchemaDto saved =
       this.createCTLSchema(
           name,
           CTL_DEFAULT_NAMESPACE,
           1,
           tenantDeveloperDto.getTenantId(),
           application.getApplicationToken(),
           null,
           null);
   FileData fd =
       client.downloadCtlSchemaByAppToken(
           client.getCTLSchemaById(saved.getId()),
           CTLSchemaExportMethod.FLAT,
           application.getApplicationToken());
   Assert.assertNotNull(fd);
   Schema loaded = new Parser().parse(new String(fd.getFileData()));
   Assert.assertEquals(name, loaded.getName());
 }
  /**
   * Check existence of CTL schema with same fqn and another scope
   *
   * @throws Exception
   */
  @Test
  public void checkCTLFqnExistsTest() throws Exception {
    this.loginTenantDeveloper(tenantDeveloperUser);
    CTLSchemaDto saved =
        this.createCTLSchema(
            this.ctlRandomFieldType(),
            CTL_DEFAULT_NAMESPACE,
            1,
            tenantDeveloperDto.getTenantId(),
            null,
            null,
            null);
    String fqn = saved.getMetaInfo().getFqn();
    boolean result = client.checkFqnExistsWithAppToken(fqn, tenantDeveloperDto.getTenantId(), null);
    Assert.assertFalse(result);
    result = client.checkFqnExistsWithAppToken(fqn, null, null);
    Assert.assertFalse(result);

    ApplicationDto application1 = createApplication(tenantAdminDto);
    ApplicationDto application2 = createApplication(tenantAdminDto);
    this.loginTenantDeveloper(tenantDeveloperUser);
    CTLSchemaDto schema1 =
        this.createCTLSchema(
            "TestAppFqn1",
            CTL_DEFAULT_NAMESPACE,
            1,
            tenantDeveloperDto.getTenantId(),
            application1.getApplicationToken(),
            null,
            null);
    this.createCTLSchema(
        "TestAppFqn1",
        CTL_DEFAULT_NAMESPACE,
        1,
        tenantDeveloperDto.getTenantId(),
        application2.getApplicationToken(),
        null,
        null);

    fqn = schema1.getMetaInfo().getFqn();

    result =
        client.checkFqnExistsWithAppToken(
            fqn, tenantDeveloperDto.getTenantId(), application1.getApplicationToken());
    Assert.assertTrue(result);

    result =
        client.checkFqnExistsWithAppToken(
            fqn, tenantDeveloperDto.getTenantId(), application2.getApplicationToken());
    Assert.assertTrue(result);

    result = client.checkFqnExistsWithAppToken(fqn, tenantDeveloperDto.getTenantId(), null);
    Assert.assertFalse(result);
  }
Esempio n. 12
0
 @Test
 public void registerProfileServiceTest() throws IOException {
   byte[] profile = baseAvroConverter.encode(ENDPOINT_PROFILE);
   RegisterProfileRequest request =
       new RegisterProfileRequest(
           application.getApplicationToken(), ENDPOINT_KEY, sdkToken, profile);
   EndpointProfileDto dto = profileService.registerProfile(request);
   Assert.assertNotNull(dto);
   Assert.assertNotNull(dto.getId());
   Assert.assertTrue(Arrays.equals(ENDPOINT_KEY, dto.getEndpointKey()));
   Assert.assertTrue(
       Arrays.equals(
           EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData(), dto.getEndpointKeyHash()));
   Assert.assertEquals(
       baseAvroConverter.encodeToJson(ENDPOINT_PROFILE),
       dto.getClientProfileBody().replaceAll(" ", ""));
   Assert.assertTrue(
       Arrays.equals(EndpointObjectHash.fromSha1(profile).getData(), dto.getProfileHash()));
 }
Esempio n. 13
0
  @Before
  public void beforeTest() throws IOException, DeltaCalculatorException, ControlServiceException {
    String dataSchema =
        OperationsServiceIT.getResourceAsString(OperationsServiceIT.DATA_SCHEMA_LOCATION);
    PROFILE_BYTES = avroConverter.encode(ENDPOINT_PROFILE);
    PROFILE_JSON = avroConverter.encodeToJson(ENDPOINT_PROFILE);

    tenant = new TenantDto();
    tenant.setName(CUSTOMER_ID);
    tenant = userService.saveTenant(tenant);
    assertNotNull(tenant);
    assertNotNull(tenant.getId());

    ApplicationDto applicationDto = new ApplicationDto();
    applicationDto.setTenantId(tenant.getId());
    applicationDto.setApplicationToken(APPLICATION_ID);
    applicationDto.setName(APPLICATION_NAME);
    applicationDto.setSequenceNumber(NEW_APPLICATION_SEQ_NUMBER);
    applicationDto = applicationService.saveApp(applicationDto);
    APP_TOKEN = applicationDto.getApplicationToken();
    assertNotNull(applicationDto);
    assertNotNull(applicationDto.getId());

    application = applicationService.findAppById(applicationDto.getId());

    EndpointGroupDto groupAll =
        endpointService.findEndpointGroupsByAppId(application.getId()).get(0);

    CTLSchemaDto profileCtlSchema = new CTLSchemaDto();
    CtlSchemaMetaInfoDto metaInfo =
        new CtlSchemaMetaInfoDto(
            BasicEndpointProfile.SCHEMA$.getFullName(),
            application.getTenantId(),
            application.getId());
    profileCtlSchema.setMetaInfo(metaInfo);
    profileCtlSchema.setBody(BasicEndpointProfile.SCHEMA$.toString());
    profileCtlSchema.setVersion(1);
    profileCtlSchema.setDependencySet(new HashSet<CTLSchemaDto>());
    profileCtlSchema = ctlService.saveCtlSchema(profileCtlSchema);

    Schema schema = new Schema.Parser().parse(dataSchema);
    CTLSchemaDto confCtlSchema = new CTLSchemaDto();
    CtlSchemaMetaInfoDto confMetaInfo =
        new CtlSchemaMetaInfoDto(
            schema.getFullName(), application.getTenantId(), application.getId());
    confCtlSchema.setMetaInfo(confMetaInfo);
    confCtlSchema.setBody(schema.toString());
    confCtlSchema.setVersion(CONF_SCHEMA_VERSION);
    confCtlSchema.setDependencySet(new HashSet<CTLSchemaDto>());
    confCtlSchema = ctlService.saveCtlSchema(confCtlSchema);

    EndpointProfileSchemaDto profileSchemaObj = new EndpointProfileSchemaDto();
    profileSchemaObj.setVersion(PROFILE_SCHEMA_VERSION);
    profileSchemaObj.setCtlSchemaId(profileCtlSchema.getId());
    profileSchemaObj.setApplicationId(application.getId());
    EndpointProfileSchemaDto profileSchemaDto = profileService.saveProfileSchema(profileSchemaObj);

    profileSchema = profileService.findProfileSchemaById(profileSchemaDto.getId());

    EndpointGroupDto endpointGroup = new EndpointGroupDto();
    endpointGroup.setApplicationId(application.getId());
    endpointGroup.setName("Test group");
    endpointGroup.setWeight(277);
    endpointGroup.setDescription("Test Description");
    endpointGroup = endpointService.saveEndpointGroup(endpointGroup);

    ProfileFilterDto profileFilterObj = new ProfileFilterDto();
    profileFilterObj.setApplicationId(application.getId());
    profileFilterObj.setEndpointGroupId(endpointGroup.getId());
    profileFilterObj.setBody("profileBody.contains(\"dummy\")");
    profileFilterObj.setEndpointProfileSchemaId(profileSchema.getId());
    profileFilter = profileService.saveProfileFilter(profileFilterObj);
    profileService.activateProfileFilter(profileFilter.getId(), null);

    confSchema = new ConfigurationSchemaDto();
    confSchema.setApplicationId(application.getId());
    confSchema.setVersion(CONF_SCHEMA_VERSION);
    confSchema.setCtlSchemaId(confCtlSchema.getId());

    try {
      confSchema = configurationService.saveConfSchema(confSchema);
    } catch (IncorrectParameterException e) {
      Assert.fail("Can't generate schemas");
    }
    Assert.assertNotNull(confSchema);
    Assert.assertNotNull(confSchema.getId());

    egAllId = groupAll.getId();
    pfAllId = profileFilter.getId();
    ConfigurationDto confDto =
        configurationService.findConfigurationByEndpointGroupIdAndVersion(
            egAllId, CONF_SCHEMA_VERSION);
    cfAllId = confDto.getId();

    endpointConfiguration = new EndpointConfigurationDto();
    endpointConfiguration.setConfiguration(confDto.getBody().getBytes(UTF_8));
    endpointConfiguration.setConfigurationHash(
        EndpointObjectHash.fromSha1(confDto.getBody()).getData());
    endpointConfiguration = endpointService.saveEndpointConfiguration(endpointConfiguration);
    assertNotNull(endpointConfiguration);

    EndpointGroupStateDto egs = new EndpointGroupStateDto();
    egs.setConfigurationId(cfAllId);
    egs.setEndpointGroupId(egAllId);
    egs.setProfileFilterId(pfAllId);

    endpointProfile = new EndpointProfileDto();
    endpointProfile.setApplicationId(application.getId());
    endpointProfile.setEndpointKeyHash(Base64Utils.decodeFromString("EndpointId"));
    endpointProfile.setClientProfileBody(PROFILE_JSON);
    endpointProfile.setProfileHash(EndpointObjectHash.fromSha1(PROFILE_BYTES).getData());
    endpointProfile.setConfigurationHash(endpointConfiguration.getConfigurationHash());
    endpointProfile.setConfigurationVersion(CONF_SCHEMA_VERSION);
    endpointProfile.setClientProfileVersion(PROFILE_VERSION);
    endpointProfile.setGroupState(Collections.singletonList(egs));
    endpointProfile = endpointService.saveEndpointProfile(endpointProfile);
    assertNotNull(endpointProfile);
    assertNotNull(endpointProfile.getId());
  }
  @Override
  protected void buildDemoApplicationImpl(AdminClient client) throws Exception {

    logger.info("Loading 'City lights controller application' data...");

    loginTenantAdmin(client);

    ApplicationDto cityLightsDemoApplication = new ApplicationDto();
    cityLightsDemoApplication.setName("City lights controller demo");
    cityLightsDemoApplication = client.editApplication(cityLightsDemoApplication);
    sdkPropertiesDto.setApplicationId(cityLightsDemoApplication.getId());
    sdkPropertiesDto.setProfileSchemaVersion(1);
    sdkPropertiesDto.setNotificationSchemaVersion(1);
    sdkPropertiesDto.setLogSchemaVersion(1);

    loginTenantDeveloper(client);

    logger.info("Creating configuration schema...");
    ConfigurationSchemaDto configurationSchema = new ConfigurationSchemaDto();
    configurationSchema.setApplicationId(cityLightsDemoApplication.getId());
    configurationSchema.setName("City lights controller schema");
    configurationSchema.setDescription(
        "Default configuration schema for the city lights controller application");
    configurationSchema =
        client.createConfigurationSchema(
            configurationSchema, getResourcePath("config_schema.avsc"));
    logger.info("Configuration schema version: {}", configurationSchema.getMajorVersion());
    sdkPropertiesDto.setConfigurationSchemaVersion(configurationSchema.getMajorVersion());
    logger.info("Configuration schema was created.");

    EndpointGroupDto baseEndpointGroup = null;
    List<EndpointGroupDto> endpointGroups =
        client.getEndpointGroups(cityLightsDemoApplication.getId());
    if (endpointGroups.size() == 1 && endpointGroups.get(0).getWeight() == 0) {
      baseEndpointGroup = endpointGroups.get(0);
    }

    if (baseEndpointGroup == null) {
      throw new RuntimeException(
          "Can't get default endpoint group for the city lights controller application!");
    }

    ConfigurationDto baseConfiguration = new ConfigurationDto();
    baseConfiguration.setApplicationId(cityLightsDemoApplication.getId());
    baseConfiguration.setEndpointGroupId(baseEndpointGroup.getId());
    baseConfiguration.setSchemaId(configurationSchema.getId());
    baseConfiguration.setMajorVersion(configurationSchema.getMajorVersion());
    baseConfiguration.setMinorVersion(configurationSchema.getMinorVersion());
    baseConfiguration.setDescription("Base city lights controller configuration");
    String body = FileUtils.readResource(getResourcePath("config_data.json"));
    logger.info("Configuration body: [{}]", body);

    ObjectMapper objectMapper = new ObjectMapper();
    Map<String, Object> configBody = objectMapper.readValue(body, Map.class);
    logger.info("Getting config body: [{}]", configBody);
    Map<String, Object> kaaClientConfig = (Map<String, Object>) configBody.get(KAA_CLIENT_CONFIG);
    logger.info("Getting kaaClientConfig: [{}]", kaaClientConfig);
    logger.info("Getting traffic lights and traffic lights app tokens...");
    List<ApplicationDto> applications = client.getApplications();
    logger.info("All available applications: [{}]", applications);
    ApplicationDto trafficLightsApplication =
        getApplicationWithName(applications, TRAFFIC_LIGHTS_APPLICATION_NAME);
    if (trafficLightsApplication == null) {
      logger.error(formErrorLogMessage(TRAFFIC_LIGHTS_APPLICATION_NAME));
      throw new RuntimeException(
          "Can't get '" + TRAFFIC_LIGHTS_APPLICATION_NAME + "' application!");
    }
    logger.info(
        TRAFFIC_LIGHTS_APPLICATION_NAME + " application was found: {}", trafficLightsApplication);
    ApplicationDto streetLightApplication =
        getApplicationWithName(applications, STREET_LIGHT_APPLICATION_NAME);
    if (streetLightApplication == null) {
      logger.error(formErrorLogMessage(STREET_LIGHT_APPLICATION_NAME));
      throw new RuntimeException("Can't get '" + STREET_LIGHT_APPLICATION_NAME + "' application!");
    }
    logger.info(
        STREET_LIGHT_APPLICATION_NAME + " application was found: {}", streetLightApplication);
    kaaClientConfig.put(
        TRAFFIC_LIGHTS_APP_TOKEN_PROPERTY, trafficLightsApplication.getApplicationToken());
    kaaClientConfig.put(
        STREET_LIGHT_APP_TOKEN_PROPERTY, streetLightApplication.getApplicationToken());
    body = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(configBody);
    logger.info("Configuration body after altering: [{}]", body);
    baseConfiguration.setBody(body);
    baseConfiguration.setStatus(UpdateStatus.INACTIVE);
    logger.info("Editing the configuration...");
    baseConfiguration = client.editConfiguration(baseConfiguration);
    logger.info("Configuration was successfully edited");
    logger.info("Activating the configuration");
    client.activateConfiguration(baseConfiguration.getId());
    logger.info("Configuration was activated");

    logger.info("Finished loading 'City lights controller application' data...");
  }
  @Override
  protected void buildDemoApplicationImpl(AdminClient client) throws Exception {

    logger.info("Loading 'Street lights driver application' data...");

    loginTenantAdmin(client);

    ApplicationDto streetLightApplication = new ApplicationDto();
    streetLightApplication.setName("Street light driver");
    streetLightApplication = client.editApplication(streetLightApplication);

    sdkProfileDto.setApplicationId(streetLightApplication.getId());
    sdkProfileDto.setProfileSchemaVersion(0);
    sdkProfileDto.setNotificationSchemaVersion(1);
    sdkProfileDto.setLogSchemaVersion(1);
    sdkProfileDto.setConfigurationSchemaVersion(1);

    loginTenantDeveloper(client);

    logger.info("Creating profile schema...");

    CTLSchemaInfoDto profileCtlSchema =
        client.saveCTLSchema(
            getResourceAsString("profile.avsc"),
            CTLSchemaScopeDto.PROFILE_SCHEMA,
            streetLightApplication.getId());

    EndpointProfileSchemaDto profileSchemaDto = new EndpointProfileSchemaDto();
    profileSchemaDto.setApplicationId(streetLightApplication.getId());
    profileSchemaDto.setName("StreetLightsDriverProfile schema");
    profileSchemaDto.setDescription("Street light driver profile schema");
    profileSchemaDto.setCtlSchemaId(profileCtlSchema.getId());
    profileSchemaDto = client.saveProfileSchema(profileSchemaDto);
    logger.info("Profile schema version: {}", profileSchemaDto.getVersion());
    sdkProfileDto.setProfileSchemaVersion(profileSchemaDto.getVersion());
    logger.info("Profile schema was created.");

    logger.info("Creating configuration schema...");
    ConfigurationSchemaDto configurationSchema = new ConfigurationSchemaDto();
    configurationSchema.setApplicationId(streetLightApplication.getId());
    configurationSchema.setName("StreetLightsConfiguration schema");
    configurationSchema.setDescription("Street Light configuration schema");
    configurationSchema =
        client.createConfigurationSchema(
            configurationSchema, getResourcePath("configuration.avsc"));
    logger.info("Configuration schema version: {}", configurationSchema.getVersion());
    sdkProfileDto.setConfigurationSchemaVersion(configurationSchema.getVersion());
    logger.info("Configuration schema was created");

    for (int i = 0; i < LIGHT_ZONE_COUNT; ++i) {
      EndpointGroupDto group = new EndpointGroupDto();
      group.setApplicationId(streetLightApplication.getId());
      group.setName("Zone " + Integer.toString(i));
      group.setWeight(i + 1);
      logger.info("Creating Endpoint group for Light Zone {}", i);
      group = client.editEndpointGroup(group);
      logger.info("Created Endpoint group for Light Zone {}", i);

      ProfileFilterDto filter = new ProfileFilterDto();
      filter.setApplicationId(streetLightApplication.getId());
      filter.setEndpointGroupId(group.getId());
      filter.setEndpointProfileSchemaId(profileSchemaDto.getId());
      filter.setEndpointProfileSchemaVersion(profileSchemaDto.getVersion());
      filter.setBody("lightZones.contains(new Integer(" + Integer.toString(i) + "))");
      filter.setStatus(UpdateStatus.INACTIVE);
      logger.info("Creating Profile filter for Light Zone {}", i);
      filter = client.editProfileFilter(filter);
      logger.info("Activating Profile filter for Light Zone {}", i);
      client.activateProfileFilter(filter.getId());
      logger.info("Created and activated Profile filter for Light Zone {}", i);

      ConfigurationDto baseGroupConfiguration = new ConfigurationDto();
      baseGroupConfiguration.setApplicationId(streetLightApplication.getId());
      baseGroupConfiguration.setEndpointGroupId(group.getId());
      baseGroupConfiguration.setSchemaId(configurationSchema.getId());
      baseGroupConfiguration.setSchemaVersion(configurationSchema.getVersion());
      baseGroupConfiguration.setDescription("Base street light driver configuration");
      String body = getConfigurationBodyForEndpointGroup(i);
      logger.info("Configuration body: [{}]", body);
      baseGroupConfiguration.setBody(body);
      logger.info("Editing the configuration...");
      baseGroupConfiguration = client.editConfiguration(baseGroupConfiguration);
      logger.info("Configuration was successfully edited");
      logger.info("Activating the configuration");
      client.activateConfiguration(baseGroupConfiguration.getId());
      logger.info("Configuration was activated");
    }

    logger.info("Finished loading 'Street lights driver application' data...");
  }
Esempio n. 16
0
  @Before
  public void beforeTest() throws IOException, SQLException {
    clearDBData();
    tenant = new TenantDto();
    tenant.setName(CUSTOMER_NAME);
    tenant = userService.saveTenant(tenant);

    application = new ApplicationDto();
    application.setName(APP_NAME);
    application.setTenantId(tenant.getId());
    application = applicationService.saveApp(application);

    CtlSchemaMetaInfoDto ctl1MetaDataDto =
        new CtlSchemaMetaInfoDto(EmptyData.SCHEMA$.getFullName(), null, null);
    CTLSchemaDto ctl1SchemaDto = new CTLSchemaDto();
    ctl1SchemaDto.setMetaInfo(ctl1MetaDataDto);
    ctl1SchemaDto.setVersion(2);
    ctl1SchemaDto.setBody(EmptyData.SCHEMA$.toString());
    ctl1SchemaDto = ctlService.saveCtlSchema(ctl1SchemaDto);

    schema1Dto = new EndpointProfileSchemaDto();
    schema1Dto.setVersion(PROFILE_SCHEMA_VERSION);
    schema1Dto.setCtlSchemaId(ctl1SchemaDto.getId());
    schema1Dto.setApplicationId(application.getId());
    schema1Dto = daoProfileService.saveProfileSchema(schema1Dto);

    CtlSchemaMetaInfoDto ctl2MetaDataDto =
        new CtlSchemaMetaInfoDto(
            BasicEndpointProfile.SCHEMA$.getFullName(),
            application.getTenantId(),
            application.getId());
    CTLSchemaDto ctl2SchemaDto = new CTLSchemaDto();
    ctl2SchemaDto.setMetaInfo(ctl2MetaDataDto);
    ctl2SchemaDto.setVersion(2);
    ctl2SchemaDto.setBody(BasicEndpointProfile.SCHEMA$.toString());
    ctl2SchemaDto = ctlService.saveCtlSchema(ctl2SchemaDto);

    schema2Dto = new EndpointProfileSchemaDto();
    schema2Dto.setVersion(NEW_PROFILE_SCHEMA_VERSION);
    schema2Dto.setCtlSchemaId(ctl2SchemaDto.getId());
    schema2Dto.setApplicationId(application.getId());
    schema2Dto = daoProfileService.saveProfileSchema(schema2Dto);

    SdkProfileDto sdkPropertiesDto = new SdkProfileDto();
    sdkPropertiesDto.setApplicationId(application.getId());
    sdkPropertiesDto.setProfileSchemaVersion(PROFILE_SCHEMA_VERSION);
    sdkPropertiesDto.setConfigurationSchemaVersion(1);
    sdkPropertiesDto.setNotificationSchemaVersion(1);
    sdkPropertiesDto.setLogSchemaVersion(1);
    sdkPropertiesDto.setApplicationToken(application.getApplicationToken());
    sdkPropertiesDto = sdkProfileService.saveSdkProfile(sdkPropertiesDto);
    sdkToken = new SdkProfile(sdkPropertiesDto).getToken();

    SdkProfileDto newSdkProfileDto = new SdkProfileDto();
    newSdkProfileDto.setApplicationId(application.getId());
    newSdkProfileDto.setProfileSchemaVersion(NEW_PROFILE_SCHEMA_VERSION);
    newSdkProfileDto.setConfigurationSchemaVersion(1);
    newSdkProfileDto.setNotificationSchemaVersion(1);
    newSdkProfileDto.setLogSchemaVersion(1);
    newSdkProfileDto.setApplicationToken(application.getApplicationToken());
    newSdkProfileDto = sdkProfileService.saveSdkProfile(newSdkProfileDto);
    newSdkToken = new SdkProfile(newSdkProfileDto).getToken();
  }