Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature sc rxda #40

Merged
merged 23 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
afe5028
Intial commit of endpoints needed (not working stat)
gcsantos-gpa May 9, 2022
a47ee4f
Added new UserIdName view for XDA model
gcsantos-gpa May 11, 2022
680c930
Removed UserIdName, unneccessary model.
gcsantos-gpa May 11, 2022
38fbbc4
Changes to datapush engine and Datapush models to reflect change in l…
gcsantos-gpa Jun 1, 2022
d185a18
Added unique keys to assets and meters to datapush tables
gcsantos-gpa Jun 23, 2022
ff811d8
Fixed bugs associated with pushing remote instance info to other DBs
gcsantos-gpa Jul 5, 2022
ac24e9e
Fixed data pusher bugs with file pushing
gcsantos-gpa Jul 8, 2022
c3d22ff
Fixed rebasing error
gcsantos-gpa Jul 29, 2022
8dd6575
Added test connection endpoint, changed asset pushing within meter pu…
gcsantos-gpa Jul 29, 2022
02f11d3
Update Source/Libraries/openXDA.Nodes/Types/DataPusher/DataPusherNode.cs
gcsantos-gpa Aug 1, 2022
95e0782
Update Source/Libraries/openXDA.Model/SystemCenter/RemoteXDAAsset.cs
gcsantos-gpa Aug 1, 2022
8697da0
Update Source/Libraries/openXDA.Model/SystemCenter/RemoteXDAMeter.cs
gcsantos-gpa Aug 1, 2022
5cb48cc
Update Source/Libraries/openXDA.Model/SystemCenter/RemoteXDAMeter.cs
gcsantos-gpa Aug 1, 2022
3602b0e
Update Source/Libraries/openXDA.Model/SystemCenter/RemoteXDAAsset.cs
gcsantos-gpa Aug 1, 2022
4060ea7
Removed resolved TODO comment and removed superfluous const string in…
gcsantos-gpa Aug 1, 2022
0f579d3
Update Source/Data/01 - openXDA.sql
gcsantos-gpa Aug 1, 2022
17e243b
Update Source/Libraries/openXDA.Configuration/DataPusherSection.cs
gcsantos-gpa Aug 1, 2022
7cad91d
Added suggested github merge request changes.
gcsantos-gpa Aug 1, 2022
29d79b1
Added setting id for local clients when connected to openXDA. Use cas…
gcsantos-gpa Jul 29, 2022
5c80ae9
Added foreign key constraint to Meters/AssetsToDataPush Tables
gcsantos-gpa Aug 1, 2022
b9654f1
Update 01 - openXDA.sql
StephenCWills Aug 1, 2022
b6c6f12
General cleanup, mainly usings and whitespace
StephenCWills Aug 1, 2022
b725222
merged master
clackner-gpa Aug 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public IHttpActionResult SendMeterConfigurationForInstance(int instanceId, Cance
if (!response.IsSuccessStatusCode)
throw new InvalidOperationException($"Server returned status code {response.StatusCode}: {response.ReasonPhrase}");

connection.ExecuteNonQuery("UPDATE MetersToDataPush SET Synced = 1 WHERE ID IN ( SELECT MetersToDataPushID FROM RemoteXDAInstanceMeter WHERE RemoteXDAInstanceID = {0})", instance.ID);
connection.ExecuteNonQuery("UPDATE MetersToDataPush SET Synced = 1 WHERE RemoteXDAInstanceID = {0}", instance.ID);
return Ok(connectionID);
}
}
Expand Down Expand Up @@ -411,24 +411,23 @@ public Task SyncInstanceConfiguration(string connectionId, int instanceId, Cance
DataPusherEngine engine = new DataPusherEngine(() => new AdoDataConnection("systemSettings"));
engine.SyncInstanceConfiguration(connectionId, instanceId, cancellationToken);
}, cancellationToken);

}

[Route("SyncInstanceFiles/{connectionId}/{instanceId:int}"), HttpGet]
public Task SyncFilesForInstance(string connectionId, int instanceId, CancellationToken cancellationToken)
[Route("TestConnection/{instanceId:int}"), HttpGet]
public IHttpActionResult TestRemoteInstanceConnection(int instanceId)
{
return Task.Run(() =>
try
{
using (AdoDataConnection connection = ConnectionFactory())
{
// for now, create new instance of DataPusherEngine. Later have one running in XDA ServiceHost and tie to it to ensure multiple updates arent happening simultaneously
DataPusherEngine engine = new DataPusherEngine(() => new AdoDataConnection("systemSettings"));
RemoteXDAInstance instance = new TableOperations<RemoteXDAInstance>(connection).QueryRecordWhere("ID = {0}", instanceId);
engine.SyncInstanceFiles(connectionId, instance, cancellationToken);
}
}, cancellationToken);
}
// for now, create new instance of DataPusherEngine. Later have one running in XDA ServiceHost and tie to it to ensure multiple updates arent happening simultaneously
DataPusherEngine engine = new DataPusherEngine(() => new AdoDataConnection("systemSettings"));
return Ok(engine.TestInstance(instanceId) ? 1 : 0);
}
catch (Exception ex)
{
return InternalServerError(ex);
}

}
private static readonly ILog Log = LogManager.GetLogger(typeof(DataPusherController));
}
}
51 changes: 25 additions & 26 deletions Source/Data/01 - openXDA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ GO
INSERT INTO NodeType VALUES('Authorization', 'openXDA.Nodes.dll', 'openXDA.Nodes.Types.Authentication.AuthenticationProviderNode')
GO

INSERT INTO NodeType VALUES('DataPusher', 'openXDA.Nodes.dll', 'openXDA.Nodes.Types.DataPusher.DataPusherNode')
GO

CREATE TABLE Node
(
ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
Expand Down Expand Up @@ -310,6 +313,9 @@ GO
INSERT INTO Node VALUES((SELECT ID FROM NodeType WHERE TypeName = 'openXDA.Nodes.Types.Authentication.AuthenticationProviderNode'), NULL, 'SSO Provider', 1)
GO

INSERT INTO Node VALUES((SELECT ID FROM NodeType WHERE TypeName = 'openXDA.Nodes.Types.DataPusher.DataPusherNode'), NULL, 'Data Pusher', 1)
GO

CREATE TABLE NodeSetting
(
ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
Expand Down Expand Up @@ -3965,53 +3971,46 @@ CREATE NONCLUSTERED INDEX IX_EventNote_EventID
ON EventNote(EventID ASC)
GO

CREATE TABLE RemoteXDAInstance
(
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
Name VARCHAR(200) NOT NULL,
Address VARCHAR(200) NULL,
Frequency VARCHAR(20) NOT NULL,
UserAccountID UNIQUEIDENTIFIER NOT NULL REFERENCES UserAccount(ID)
)
GO

CREATE TABLE MetersToDataPush
(
ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
RemoteXDAInstanceID INT NOT NULL,
LocalXDAMeterID INT NOT NULL,
RemoteXDAMeterID INT NULL,
LocalXDAAssetKey varchar(200) NOT NULL,
RemoteXDAAssetKey varchar(200) NOT NULL,
RemoteXDAName varchar(200) NOT NULL,
Obsfucate bit NOT NULL,
Synced bit NOT NULL
)
GO

CREATE UNIQUE INDEX unq_remoteID_meterID ON MetersToDataPush(RemoteXDAInstanceID, LocalXDAMeterID)
GO

CREATE TABLE AssetsToDataPush
(
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
RemoteXDAInstanceID INT NOT NULL,
LocalXDAAssetID INT NOT NULL,
RemoteXDAAssetID INT NULL,
LocalXDAAssetKey VARCHAR(200) NOT NULL,
RemoteXDAAssetKey VARCHAR(200) NOT NULL,
RemoteAssetCreatedByDataPusher bit NOT NULL DEFAULT (1)
)
GO

CREATE TABLE RemoteXDAInstance
(
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
Name VARCHAR(200) NOT NULL,
Address VARCHAR(200) NULL,
Frequency VARCHAR(20) NOT NULL,
UserAccountID UNIQUEIDENTIFIER NOT NULL REFERENCES UserAccount(ID)
)
GO

CREATE TABLE RemoteXDAInstanceMeter(
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
RemoteXDAInstanceID INT NOT NULL,
MetersToDataPushID INT NOT NULL
RemoteAssetCreatedByDataPusher bit NOT NULL DEFAULT (1),
Obsfucate bit NOT NULL,
Synced bit NOT NULL
)
GO

ALTER TABLE RemoteXDAInstanceMeter WITH CHECK ADD FOREIGN KEY(RemoteXDAInstanceID)
REFERENCES RemoteXDAInstance(ID)
GO

ALTER TABLE RemoteXDAInstanceMeter WITH CHECK ADD FOREIGN KEY(MetersToDataPushID)
REFERENCES MetersToDataPush(ID)
CREATE UNIQUE INDEX unq_remoteID_assetID ON AssetsToDataPush(RemoteXDAInstanceID, LocalXDAAssetID)
GO

CREATE TABLE FileGroupLocalToRemote
Expand Down
Binary file modified Source/Dependencies/GSF/GSF.Web.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ private void PushDataToRemoteInstances(MeterDataSet meterDataSet)


TableOperations<RemoteXDAInstance> instanceTable = new TableOperations<RemoteXDAInstance>(connection);
TableOperations<MetersToDataPush> meterTable = new TableOperations<MetersToDataPush>(connection);
IEnumerable<RemoteXDAInstance> instances = instanceTable.QueryRecordsWhere("Frequency ='*' AND ID IN (SELECT RemoteXDAInstanceID FROM RemoteXDAInstanceMeter WHERE MetersToDataPushID IN (SELECT ID FROM MetersToDataPush WHERE LocalXDAMeterID = {0}) )", meterDataSet.Meter.ID);
IEnumerable<RemoteXDAInstance> instances = instanceTable.QueryRecordsWhere("Frequency ='*' AND ID IN (SELECT RemoteXDAInstanceID FROM MetersToDataPush WHERE LocalXDAMeterID = {0}) )", meterDataSet.Meter.ID);
FileGroupPost post = new FileGroupPost();

post.FileGroup = meterDataSet.FileGroup;
Expand All @@ -113,7 +112,7 @@ private void PushDataToRemoteInstances(MeterDataSet meterDataSet)
continue;
}
UserAccount userAccount = new TableOperations<UserAccount>(connection).QueryRecordWhere("ID = {0}", instance.UserAccountID);
MetersToDataPush metersToDataPush = new TableOperations<MetersToDataPush>(connection).QueryRecordWhere("LocalXDAMeterID = {0} AND ID IN (SELECT MetersToDataPushID From RemoteXDAInstanceMeter WHERE RemoteXDAInstanceID = {1})", meterDataSet.Meter.ID, instance.ID);
MetersToDataPush metersToDataPush = new TableOperations<MetersToDataPush>(connection).QueryRecordWhere("LocalXDAMeterID = {0} AND RemoteXDAInstanceID = {1}", meterDataSet.Meter.ID, instance.ID);
post.MeterKey = metersToDataPush.RemoteXDAAssetKey;
Log.Info($"Sending data to intance: {instance.Name} for FileGroup: {meterDataSet.FileGroup.ID}...");
DataPusherEngine engine = new DataPusherEngine(meterDataSet.CreateDbConnection);
Expand Down
11 changes: 10 additions & 1 deletion Source/Libraries/openXDA.Adapters/PQMarkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ record = channelTable.QueryRecordsWhere(id);

}

/// <summary>
/// Return a 1 to request
/// </summary>
/// <returns></returns>
[HttpGet]
public IHttpActionResult Alive()
{
return Ok(1);
}
#endregion

#region [ PUT Operations ]
Expand Down Expand Up @@ -479,7 +488,7 @@ public IHttpActionResult CreateRecord(string modelName, [FromBody] JObject recor

PropertyInfo assetKeyProperty = type.GetProperty("AssetKey");

if (!(assetKeyProperty is null))
if (!(assetKeyProperty is null)) //TODO: Make sure this works with asset subtypes
recordId = connection.ExecuteScalar<int>($"SELECT ID FROM {table.TableName} WHERE AssetKey = {{0}}", assetKeyProperty.GetValue(obj));
else
recordId = connection.ExecuteScalar<int>("SELECT @@Identity");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//******************************************************************************************************
// RemoteXDAInstanceMeter.cs - Gbtc
// FilePrunerSection.cs - Gbtc
//
// Copyright © 2017, Grid Protection Alliance. All Rights Reserved.
// Copyright © 2021, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
Expand All @@ -16,22 +16,24 @@
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 07/03/2017 - Billy Ernest
// 02/08/2021 - Stephen C. Wills
// Generated original version of source code.
//
//******************************************************************************************************

using GSF.Data.Model;
using System;
using System.ComponentModel;
using System.Configuration;
using GSF.Configuration;

namespace openXDA.Model
namespace openXDA.Configuration
{
public class RemoteXDAInstanceMeter
public class DataPusherSection
{
[PrimaryKey(true)]
public int ID { get; set; }
public const string CategoryName = "DataPusher";

public int RemoteXDAInstanceID { get; set; }

public int MetersToDataPushID { get; set; }
[Setting]
[DefaultValue("systemSettings")]
public string ConnectionString { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="EPRICapBankAnalyticSection.cs" />
<Compile Include="EventEmailSection.cs" />
<Compile Include="FaultLocationSection.cs" />
<Compile Include="DataPusherSection.cs" />
<Compile Include="FilePrunerSection.cs" />
<Compile Include="PQDIFSection.cs" />
<Compile Include="PQISection.cs" />
Expand Down
Loading