Skip to content

Commit

Permalink
Merge pull request #40 from GridProtectionAlliance/Feature_SC_RXDA
Browse files Browse the repository at this point in the history
Feature sc rxda
  • Loading branch information
clackner-gpa authored Aug 2, 2022
2 parents c2601d1 + b725222 commit 1826be5
Show file tree
Hide file tree
Showing 19 changed files with 538 additions and 684 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Serialization.Formatters.Binary;
Expand Down Expand Up @@ -170,7 +169,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,22 +410,14 @@ 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(() =>
{
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);
}

private static readonly ILog Log = LogManager.GetLogger(typeof(DataPusherController));
Expand Down
53 changes: 24 additions & 29 deletions Source/Data/01 - openXDA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,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 @@ -317,6 +320,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 @@ -3999,55 +4005,44 @@ 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 FOREIGN KEY REFERENCES [RemoteXDAInstance](ID),
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
Synced bit NOT NULL,
CONSTRAINT UC_MetersToDataPush_RemoteXDAInstanceID_LocalXDAMeterID UNIQUE(RemoteXDAInstanceID, LocalXDAMeterID)
)
GO

CREATE TABLE AssetsToDataPush
(
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
RemoteXDAInstanceID INT NOT NULL FOREIGN KEY REFERENCES [RemoteXDAInstance](ID),
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,
CONSTRAINT UC_AssetsToDataPush_RemoteXDAInstanceID_LocalXDAAssetID UNIQUE(RemoteXDAInstanceID, LocalXDAAssetID)
)
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)
GO

CREATE TABLE FileGroupLocalToRemote
(
ID INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
Expand Down
2 changes: 2 additions & 0 deletions Source/Data/09 - SystemCenter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,6 @@ GO
INSERT INTO [SystemCenter.Setting](Name, Value, DefaultValue) VALUES('XDA.APIKey', '', '')
GO
INSERT INTO [SystemCenter.Setting](Name, Value, DefaultValue) VALUES('XDA.APIToken', '', '')
GO
INSERT INTO [SystemCenter.Setting](Name, Value, DefaultValue) VALUES('XDA.ClientID', 'LocalXDAClient', 'LocalXDAClient')
GO
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
//
//******************************************************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -94,8 +93,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 +111,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
12 changes: 11 additions & 1 deletion Source/Libraries/openXDA.Adapters/PQMarkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ 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 +489,7 @@ public IHttpActionResult CreateRecord(string modelName, [FromBody] JObject recor

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

if (!(assetKeyProperty is null))
if (!(assetKeyProperty is null))
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
// DataPusherSection.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,22 @@
//
// 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.ComponentModel;
using System.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

0 comments on commit 1826be5

Please sign in to comment.