Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified icp_server/database/credentialsdb.mv.db
Binary file not shown.
Binary file modified icp_server/database/icpdb.mv.db
Binary file not shown.
24 changes: 24 additions & 0 deletions icp_server/graphql_api.bal
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,30 @@ service /graphql on graphqlListener {
return check storage:getDataServicesByEnvironmentAndComponent(environmentId, componentId);
}

// Get Data Sources for a specific environment and component
isolated resource function get dataSourcesByEnvironmentAndComponent(graphql:Context context, string environmentId, string componentId) returns types:DataSource[]|error {
types:UserContextV2 userContext = check extractUserContext(context);
Comment on lines +600 to +602

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
// Get Data Sources for a specific environment and component
isolated resource function get dataSourcesByEnvironmentAndComponent(graphql:Context context, string environmentId, string componentId) returns types:DataSource[]|error {
types:UserContextV2 userContext = check extractUserContext(context);
// Get Data Sources for a specific environment and component
isolated resource function get dataSourcesByEnvironmentAndComponent(graphql:Context context, string environmentId, string componentId) returns types:DataSource[]|error {
log:printInfo("Fetching data sources", environmentId = environmentId, componentId = componentId);


// Get project ID for the component (lightweight query for access control)
string projectId = check storage:getProjectIdByComponentId(componentId);

// Build scope with project, integration, and environment
types:AccessScope scope = {
orgUuid: 1,
projectUuid: projectId,
integrationUuid: componentId,
envUuid: environmentId
};

// Verify user has view, edit, or manage permission
if !check auth:hasAnyPermission(userContext.userId, [auth:PERMISSION_INTEGRATION_VIEW, auth:PERMISSION_INTEGRATION_EDIT, auth:PERMISSION_INTEGRATION_MANAGE], scope) {
log:printWarn("Attempt to access component data sources without permission", userId = userContext.userId, environmentId = environmentId, componentId = componentId);
return [];
}

return check storage:getDataSourcesByEnvironmentAndComponent(environmentId, componentId);
Comment on lines +619 to +621

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
}
return check storage:getDataSourcesByEnvironmentAndComponent(environmentId, componentId);
}
log:printDebug("Successfully retrieved data sources", environmentId = environmentId, componentId = componentId);
return check storage:getDataSourcesByEnvironmentAndComponent(environmentId, componentId);

}

// Get Registry Resources for a specific environment and component
isolated resource function get registryResourcesByEnvironmentAndComponent(graphql:Context context, string environmentId, string componentId) returns types:RegistryResource[]|error {
types:UserContextV2 userContext = check extractUserContext(context);
Expand Down
38 changes: 38 additions & 0 deletions icp_server/modules/storage/artifact_repository.bal
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,44 @@ public isolated function getDataServicesByEnvironmentAndComponent(string environ
return dataServiceList;
}

// Get Data Sources for a specific environment and component
public isolated function getDataSourcesByEnvironmentAndComponent(string environmentId, string componentId) returns types:DataSource[]|error {
Comment on lines +629 to +630

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 3

Suggested change
// Get Data Sources for a specific environment and component
public isolated function getDataSourcesByEnvironmentAndComponent(string environmentId, string componentId) returns types:DataSource[]|error {
// Get Data Sources for a specific environment and component
public isolated function getDataSourcesByEnvironmentAndComponent(string environmentId, string componentId) returns types:DataSource[]|error {
log:printInfo("Fetching data sources for environment: " + environmentId + " and component: " + componentId);

types:DataSource[] sourceList = [];
map<string[]> sourceRuntimeMap = {};

// Get all runtime IDs for this environment and component
string[] runtimeIds = check getRuntimeIdsByEnvironmentAndComponent(environmentId, componentId);

// If no runtimes found, return empty array
if runtimeIds.length() == 0 {
Comment on lines +637 to +638

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 4

Suggested change
// If no runtimes found, return empty array
if runtimeIds.length() == 0 {
// If no runtimes found, return empty array
if runtimeIds.length() == 0 {
log:printDebug("No runtime IDs found for environment: " + environmentId + " and component: " + componentId);

return sourceList;
}

// Get all Data Sources for these runtimes
foreach string runtimeId in runtimeIds {
types:DataSource[] runtimeSources = check getDataSourcesForRuntime(runtimeId);
foreach types:DataSource ds in runtimeSources {
string key = ds.name;
string[] existing = sourceRuntimeMap[key] ?: [];
if existing.length() == 0 {
sourceRuntimeMap[key] = [runtimeId];
sourceList.push(ds);
} else {
existing.push(runtimeId);
sourceRuntimeMap[key] = existing;
}
}
}

foreach int i in 0..<(sourceList.length()) {
types:DataSource ds = sourceList[i];
ds.runtimeIds = sourceRuntimeMap[ds.name] ?: [];
sourceList[i] = ds;
}

return sourceList;
}

// Get Registry Resources for a specific environment and component
public isolated function getRegistryResourcesByEnvironmentAndComponent(string environmentId, string componentId) returns types:RegistryResource[]|error {
types:RegistryResource[] resourceList = [];
Expand Down
6 changes: 3 additions & 3 deletions icp_server/modules/storage/heartbeat_repository.bal
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,10 @@ isolated function insertAdditionalMIArtifacts(types:Heartbeat heartbeat) returns
foreach types:DataSource dataSource in <types:DataSource[]>heartbeat.artifacts.dataSources {
_ = check dbClient->execute(`
INSERT INTO runtime_data_sources (
Comment on lines 695 to 697

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 5

Suggested change
foreach types:DataSource dataSource in <types:DataSource[]>heartbeat.artifacts.dataSources {
_ = check dbClient->execute(`
INSERT INTO runtime_data_sources (
foreach types:DataSource dataSource in <types:DataSource[]>heartbeat.artifacts.dataSources {
log.debug("Inserting data source: " + dataSource.name + " for runtime: " + heartbeat.runtime);
_ = check dbClient->execute(`

runtime_id, datasource_name, driver, url, state
runtime_id, datasource_name, datasource_type, driver, url, username, state
) VALUES (
${heartbeat.runtime}, ${dataSource.name}, ${dataSource.driver},
${dataSource.url}, ${dataSource.state}
${heartbeat.runtime}, ${dataSource.name}, ${dataSource.'type}, ${dataSource.driver},
${dataSource.url}, ${dataSource.username}, ${dataSource.state}
)
`);
}
Expand Down
2 changes: 1 addition & 1 deletion icp_server/modules/storage/runtime_repository.bal
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ isolated function parseCarbonAppArtifacts(json j) returns types:CarbonAppArtifac
public isolated function getDataSourcesForRuntime(string runtimeId) returns types:DataSource[]|error {
types:DataSource[] sourceList = [];
stream<types:DataSource, sql:Error?> sourceStream = dbClient->query(`
Comment on lines 525 to 526

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 6

Suggested change
types:DataSource[] sourceList = [];
stream<types:DataSource, sql:Error?> sourceStream = dbClient->query(`
types:DataSource[] sourceList = [];
log:printInfo("Fetching data sources for runtime: " + runtimeId);
stream<types:DataSource, sql:Error?> sourceStream = dbClient->query(`

SELECT datasource_name, driver, url, state
SELECT datasource_name, datasource_type, driver, url, username, state
FROM runtime_data_sources
WHERE runtime_id = ${runtimeId}
`);
Expand Down
6 changes: 6 additions & 0 deletions icp_server/modules/types/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -674,12 +674,18 @@ public type DataSource record {
name: "datasource_name"
}
string name;
@sql:Column {
name: "datasource_type"
}
string 'type?;
string driver?;
string url?;
string username?;
@sql:Column {
name: "datasource_state"
}
string state = "ENABLED"; // "ENABLED", "DISABLED"
string[] runtimeIds?;
};

public type Connector record {
Expand Down
4 changes: 4 additions & 0 deletions icp_server/resources/db/init-scripts/h2_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,10 @@ CREATE TABLE runtime_data_sources (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
runtime_id VARCHAR(100) NOT NULL,
datasource_name VARCHAR(200) NOT NULL,
datasource_type VARCHAR(100),
driver VARCHAR(500),
url VARCHAR(1000),
username VARCHAR(255),
state VARCHAR(20) NOT NULL DEFAULT 'ENABLED',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -1077,6 +1079,8 @@ CREATE INDEX idx_runtime_data_sources_runtime_id ON runtime_data_sources (runtim

CREATE INDEX idx_runtime_data_sources_datasource_name ON runtime_data_sources (datasource_name);

CREATE INDEX idx_runtime_data_sources_datasource_type ON runtime_data_sources (datasource_type);

CREATE INDEX idx_runtime_data_sources_state ON runtime_data_sources (state);

-- Connectors (MI)
Expand Down
3 changes: 3 additions & 0 deletions icp_server/resources/db/init-scripts/mysql_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,10 @@ CREATE TABLE runtime_data_sources (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
runtime_id VARCHAR(100) NOT NULL,
datasource_name VARCHAR(200) NOT NULL,
datasource_type VARCHAR(100) NULL,
driver VARCHAR(500) NULL,
url VARCHAR(1000) NULL,
username VARCHAR(255) NULL,
state ENUM(
'ENABLED',
'DISABLED',
Expand All @@ -954,6 +956,7 @@ CREATE TABLE runtime_data_sources (
UNIQUE KEY uk_runtime_data_source (runtime_id, datasource_name),
INDEX idx_runtime_id (runtime_id),
INDEX idx_datasource_name (datasource_name),
INDEX idx_datasource_type (datasource_type),
INDEX idx_state (state)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

Expand Down
Loading