private static DataFeed setDataFeedSourceType()

in sdk/metricsadvisor/azure-ai-metricsadvisor/src/main/java/com/azure/ai/metricsadvisor/implementation/util/DataFeedTransforms.java [157:331]


    private static DataFeed setDataFeedSourceType(final DataFeedDetail dataFeedDetail) {
        final DataFeedSourceType dataFeedSourceType;
        final DataFeed dataFeed = new DataFeed();

        if (dataFeedDetail instanceof AzureApplicationInsightsDataFeed) {
            final AzureApplicationInsightsParameter dataSourceParameter
                = ((AzureApplicationInsightsDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(new AzureAppInsightsDataFeedSource(dataSourceParameter.getApplicationId(),
                dataSourceParameter.getApiKey(), dataSourceParameter.getAzureCloud(), dataSourceParameter.getQuery()));
            dataFeedSourceType = DataFeedSourceType.AZURE_APP_INSIGHTS;
        } else if (dataFeedDetail instanceof AzureBlobDataFeed) {
            final AzureBlobParameter dataSourceParameter
                = ((AzureBlobDataFeed) dataFeedDetail).getDataSourceParameter();
            if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.BASIC) {
                dataFeed
                    .setSource(AzureBlobDataFeedSource.fromBasicCredential(dataSourceParameter.getConnectionString(),
                        dataSourceParameter.getContainer(), dataSourceParameter.getBlobTemplate()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.MANAGED_IDENTITY) {
                dataFeed.setSource(
                    AzureBlobDataFeedSource.fromManagedIdentityCredential(dataSourceParameter.getConnectionString(),
                        dataSourceParameter.getContainer(), dataSourceParameter.getBlobTemplate()));
            } else {
                throw LOGGER.logExceptionAsError(new RuntimeException(
                    String.format("AuthType %s not supported for Blob", dataFeedDetail.getAuthenticationType())));
            }
            dataFeedSourceType = DataFeedSourceType.AZURE_BLOB;
        } else if (dataFeedDetail instanceof AzureCosmosDBDataFeed) {
            final AzureCosmosDBParameter dataSourceParameter
                = ((AzureCosmosDBDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(new AzureCosmosDbDataFeedSource(dataSourceParameter.getConnectionString(),
                dataSourceParameter.getSqlQuery(), dataSourceParameter.getDatabase(),
                dataSourceParameter.getCollectionId()));
            dataFeedSourceType = DataFeedSourceType.AZURE_COSMOS_DB;
        } else if (dataFeedDetail instanceof AzureDataExplorerDataFeed) {
            final SqlSourceParameter dataSourceParameter
                = ((AzureDataExplorerDataFeed) dataFeedDetail).getDataSourceParameter();
            if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.BASIC) {
                dataFeed.setSource(AzureDataExplorerDataFeedSource
                    .fromBasicCredential(dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.MANAGED_IDENTITY) {
                dataFeed.setSource(AzureDataExplorerDataFeedSource.fromManagedIdentityCredential(
                    dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL) {
                dataFeed.setSource(AzureDataExplorerDataFeedSource.fromServicePrincipalCredential(
                    dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery(),
                    dataFeedDetail.getCredentialId()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL_IN_KV) {
                dataFeed.setSource(AzureDataExplorerDataFeedSource.fromServicePrincipalInKeyVaultCredential(
                    dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery(),
                    dataFeedDetail.getCredentialId()));
            } else {
                throw LOGGER.logExceptionAsError(new RuntimeException(String.format(
                    "AuthType %s not supported for AzureDataExplorer", dataFeedDetail.getAuthenticationType())));
            }
            dataFeedSourceType = DataFeedSourceType.AZURE_DATA_EXPLORER;
        } else if (dataFeedDetail instanceof AzureEventHubsDataFeed) {
            final AzureEventHubsParameter azureEventHubsParameter
                = ((AzureEventHubsDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(new AzureEventHubsDataFeedSource(azureEventHubsParameter.getConnectionString(),
                azureEventHubsParameter.getConsumerGroup()));
            dataFeedSourceType = DataFeedSourceType.AZURE_EVENT_HUBS;
        } else if (dataFeedDetail instanceof AzureTableDataFeed) {
            final AzureTableParameter dataSourceParameter
                = ((AzureTableDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(new AzureTableDataFeedSource(dataSourceParameter.getConnectionString(),
                dataSourceParameter.getQuery(), dataSourceParameter.getTable()));
            dataFeedSourceType = DataFeedSourceType.AZURE_TABLE;
        } else if (dataFeedDetail instanceof InfluxDBDataFeed) {
            final InfluxDBParameter dataSourceParameter = ((InfluxDBDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(new InfluxDbDataFeedSource(dataSourceParameter.getConnectionString(),
                dataSourceParameter.getDatabase(), dataSourceParameter.getUserName(), dataSourceParameter.getPassword(),
                dataSourceParameter.getQuery()));
            dataFeedSourceType = DataFeedSourceType.INFLUX_DB;
        } else if (dataFeedDetail instanceof MySqlDataFeed) {
            final SqlSourceParameter dataSourceParameter = ((MySqlDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(
                new MySqlDataFeedSource(dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery()));
            dataFeedSourceType = DataFeedSourceType.MYSQL_DB;
        } else if (dataFeedDetail instanceof PostgreSqlDataFeed) {
            final SqlSourceParameter dataSourceParameter
                = ((PostgreSqlDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(new PostgreSqlDataFeedSource(dataSourceParameter.getConnectionString(),
                dataSourceParameter.getQuery()));
            dataFeedSourceType = DataFeedSourceType.POSTGRE_SQL_DB;
        } else if (dataFeedDetail instanceof SQLServerDataFeed) {
            final SqlSourceParameter dataSourceParameter
                = ((SQLServerDataFeed) dataFeedDetail).getDataSourceParameter();
            if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.BASIC) {
                dataFeed.setSource(SqlServerDataFeedSource
                    .fromBasicCredential(dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.MANAGED_IDENTITY) {
                dataFeed.setSource(SqlServerDataFeedSource.fromManagedIdentityCredential(
                    dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.AZURE_SQLCONNECTION_STRING) {
                dataFeed.setSource(SqlServerDataFeedSource
                    .fromConnectionStringCredential(dataSourceParameter.getQuery(), dataFeedDetail.getCredentialId()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL) {
                dataFeed.setSource(
                    SqlServerDataFeedSource.fromServicePrincipalCredential(dataSourceParameter.getConnectionString(),
                        dataSourceParameter.getQuery(), dataFeedDetail.getCredentialId()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL_IN_KV) {
                dataFeed.setSource(SqlServerDataFeedSource.fromServicePrincipalInKeyVaultCredential(
                    dataSourceParameter.getConnectionString(), dataSourceParameter.getQuery(),
                    dataFeedDetail.getCredentialId()));
            } else {
                throw LOGGER.logExceptionAsError(new RuntimeException(String
                    .format("AuthType %s not supported for AzureSqlServer", dataFeedDetail.getAuthenticationType())));
            }
            dataFeedSourceType = DataFeedSourceType.SQL_SERVER_DB;
        } else if (dataFeedDetail instanceof MongoDBDataFeed) {
            final MongoDBParameter dataSourceParameter = ((MongoDBDataFeed) dataFeedDetail).getDataSourceParameter();
            dataFeed.setSource(new MongoDbDataFeedSource(dataSourceParameter.getConnectionString(),
                dataSourceParameter.getDatabase(), dataSourceParameter.getCommand()));
            dataFeedSourceType = DataFeedSourceType.MONGO_DB;
        } else if (dataFeedDetail instanceof AzureDataLakeStorageGen2DataFeed) {
            final AzureDataLakeStorageGen2Parameter azureDataLakeStorageGen2Parameter
                = ((AzureDataLakeStorageGen2DataFeed) dataFeedDetail).getDataSourceParameter();
            if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.BASIC) {
                dataFeed.setSource(AzureDataLakeStorageGen2DataFeedSource.fromBasicCredential(
                    azureDataLakeStorageGen2Parameter.getAccountName(),
                    azureDataLakeStorageGen2Parameter.getAccountKey(),
                    azureDataLakeStorageGen2Parameter.getFileSystemName(),
                    azureDataLakeStorageGen2Parameter.getDirectoryTemplate(),
                    azureDataLakeStorageGen2Parameter.getFileTemplate()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.DATA_LAKE_GEN2SHARED_KEY) {
                dataFeed.setSource(AzureDataLakeStorageGen2DataFeedSource.fromSharedKeyCredential(
                    azureDataLakeStorageGen2Parameter.getAccountName(),
                    azureDataLakeStorageGen2Parameter.getFileSystemName(),
                    azureDataLakeStorageGen2Parameter.getDirectoryTemplate(),
                    azureDataLakeStorageGen2Parameter.getFileTemplate(), dataFeedDetail.getCredentialId()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL) {
                dataFeed.setSource(AzureDataLakeStorageGen2DataFeedSource.fromServicePrincipalCredential(
                    azureDataLakeStorageGen2Parameter.getAccountName(),
                    azureDataLakeStorageGen2Parameter.getFileSystemName(),
                    azureDataLakeStorageGen2Parameter.getDirectoryTemplate(),
                    azureDataLakeStorageGen2Parameter.getFileTemplate(), dataFeedDetail.getCredentialId()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL_IN_KV) {
                dataFeed.setSource(AzureDataLakeStorageGen2DataFeedSource.fromServicePrincipalInKeyVaultCredential(
                    azureDataLakeStorageGen2Parameter.getAccountName(),
                    azureDataLakeStorageGen2Parameter.getFileSystemName(),
                    azureDataLakeStorageGen2Parameter.getDirectoryTemplate(),
                    azureDataLakeStorageGen2Parameter.getFileTemplate(), dataFeedDetail.getCredentialId()));
            } else {
                throw LOGGER.logExceptionAsError(new RuntimeException(String.format(
                    "AuthType %s not supported for AzureDataLakeStorageGen2", dataFeedDetail.getAuthenticationType())));
            }
            dataFeedSourceType = DataFeedSourceType.AZURE_DATA_LAKE_STORAGE_GEN2;
        } else if (dataFeedDetail instanceof AzureLogAnalyticsDataFeed) {
            final AzureLogAnalyticsParameter azureLogAnalyticsDataFeed
                = ((AzureLogAnalyticsDataFeed) dataFeedDetail).getDataSourceParameter();
            if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.BASIC) {
                dataFeed.setSource(
                    AzureLogAnalyticsDataFeedSource.fromBasicCredential(azureLogAnalyticsDataFeed.getTenantId(),
                        azureLogAnalyticsDataFeed.getClientId(), azureLogAnalyticsDataFeed.getClientSecret(),
                        azureLogAnalyticsDataFeed.getWorkspaceId(), azureLogAnalyticsDataFeed.getQuery()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL) {
                dataFeed.setSource(AzureLogAnalyticsDataFeedSource.fromServicePrincipalCredential(
                    azureLogAnalyticsDataFeed.getWorkspaceId(), azureLogAnalyticsDataFeed.getQuery(),
                    dataFeedDetail.getCredentialId()));
            } else if (dataFeedDetail.getAuthenticationType() == AuthenticationTypeEnum.SERVICE_PRINCIPAL_IN_KV) {
                dataFeed.setSource(AzureLogAnalyticsDataFeedSource.fromServicePrincipalInKeyVaultCredential(
                    azureLogAnalyticsDataFeed.getWorkspaceId(), azureLogAnalyticsDataFeed.getQuery(),
                    dataFeedDetail.getCredentialId()));
            } else {
                throw LOGGER.logExceptionAsError(new RuntimeException(String.format(
                    "AuthType %s not supported for AzureLogAnalytics", dataFeedDetail.getAuthenticationType())));
            }
            dataFeedSourceType = DataFeedSourceType.AZURE_LOG_ANALYTICS;
        } else {
            throw LOGGER.logExceptionAsError(new RuntimeException(
                String.format("Data feed source type %s not supported", dataFeedDetail.getClass().getCanonicalName())));
        }
        DataFeedHelper.setSourceType(dataFeed, dataFeedSourceType);
        return dataFeed;
    }