コード例 #1
0
  @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...");
  }
コード例 #2
0
  @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...");
  }