@RequestMapping( value = "/{configName}", method = {RequestMethod.DELETE}) @ResponseBody public void deleteConfig(@PathVariable String configName) throws IOException { StreamingConfig config = streamingService.getStreamingManager().getStreamingConfig(configName); KafkaConfig kafkaConfig = kafkaConfigService.getKafkaConfig(configName); if (null == config) { throw new NotFoundException("StreamingConfig with name " + configName + " not found.."); } try { streamingService.dropStreamingConfig(config); kafkaConfigService.dropKafkaConfig(kafkaConfig); } catch (Exception e) { logger.error(e.getLocalizedMessage(), e); throw new InternalErrorException( "Failed to delete StreamingConfig. " + " Caused by: " + e.getMessage(), e); } }
/** * create Streaming Schema * * @throws java.io.IOException */ @RequestMapping( value = "", method = {RequestMethod.POST}) @ResponseBody public StreamingRequest saveStreamingConfig(@RequestBody StreamingRequest streamingRequest) { String project = streamingRequest.getProject(); TableDesc tableDesc = deserializeTableDesc(streamingRequest); StreamingConfig streamingConfig = deserializeSchemalDesc(streamingRequest); KafkaConfig kafkaConfig = deserializeKafkaSchemalDesc(streamingRequest); boolean saveStreamingSuccess = false, saveKafkaSuccess = false; try { tableDesc.setUuid(UUID.randomUUID().toString()); MetadataManager metaMgr = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv()); metaMgr.saveSourceTable(tableDesc); cubeMgmtService.syncTableToProject(new String[] {tableDesc.getIdentity()}, project); } catch (IOException e) { throw new BadRequestException("Failed to add streaming table."); } streamingConfig.setName(tableDesc.getIdentity()); kafkaConfig.setName(tableDesc.getIdentity()); try { if (StringUtils.isEmpty(streamingConfig.getName())) { logger.info("StreamingConfig should not be empty."); throw new BadRequestException("StremingConfig name should not be empty."); } try { streamingConfig.setUuid(UUID.randomUUID().toString()); streamingService.createStreamingConfig(streamingConfig); saveStreamingSuccess = true; } catch (IOException e) { logger.error("Failed to save StreamingConfig:" + e.getLocalizedMessage(), e); throw new InternalErrorException( "Failed to save StreamingConfig: " + e.getLocalizedMessage()); } try { kafkaConfig.setUuid(UUID.randomUUID().toString()); kafkaConfigService.createKafkaConfig(kafkaConfig); saveKafkaSuccess = true; } catch (IOException e) { try { streamingService.dropStreamingConfig(streamingConfig); } catch (IOException e1) { throw new InternalErrorException( "StreamingConfig is created, but failed to create KafkaConfig: " + e.getLocalizedMessage()); } logger.error("Failed to save KafkaConfig:" + e.getLocalizedMessage(), e); throw new InternalErrorException("Failed to save KafkaConfig: " + e.getLocalizedMessage()); } } finally { if (saveKafkaSuccess == false || saveStreamingSuccess == false) { if (saveStreamingSuccess == true) { StreamingConfig sConfig = streamingService.getStreamingManager().getStreamingConfig(streamingConfig.getName()); try { streamingService.dropStreamingConfig(sConfig); } catch (IOException e) { throw new InternalErrorException( "Action failed and failed to rollback the created streaming config: " + e.getLocalizedMessage()); } } if (saveKafkaSuccess == true) { try { KafkaConfig kConfig = kafkaConfigService.getKafkaConfig(kafkaConfig.getName()); kafkaConfigService.dropKafkaConfig(kConfig); } catch (IOException e) { throw new InternalErrorException( "Action failed and failed to rollback the created kafka config: " + e.getLocalizedMessage()); } } } } streamingRequest.setSuccessful(true); return streamingRequest; }