* Changed Branch to Dev

* Changes to set up

* Got rid of Crayola 64

* added csv files back in

* BCP Changes

* Rescripted DB

* made ui pw false

* change to master

* added sleep timer

* added some comments

* moved sleep to end
This commit is contained in:
v-robwhi 2018-03-02 13:24:03 -08:00 коммит произвёл GitHub
Родитель a8af0e2d38
Коммит 680e7e2fb3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 204105 добавлений и 378 удалений

10001
Data/loan_info_10k.csv Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

10001
Data/member_info_10k.csv Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

183766
Data/payments_info_10k.csv Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,19 +1,19 @@
[CmdletBinding()]
param(
[parameter(Mandatory=$true, Position=1)]
[string]$ServerName,
[parameter(Mandatory = $true, Position = 1)]
[string]$ServerName,
[parameter(Mandatory=$true, Position=2)]
[string]$SolutionName,
[parameter(Mandatory = $true, Position = 2)]
[string]$SolutionName,
[parameter(Mandatory=$true, Position=3)]
[string]$InstallPy,
[parameter(Mandatory = $true, Position = 3)]
[string]$InstallPy,
[parameter(Mandatory=$true, Position=4)]
[string]$InstallR,
[parameter(Mandatory = $true, Position = 4)]
[string]$InstallR,
[parameter(Mandatory=$true, Position=5)]
[string]$Prompt
[parameter(Mandatory = $true, Position = 5)]
[string]$Prompt
)
@ -62,13 +62,13 @@ $query =
$isCompatible = Invoke-Sqlcmd -ServerInstance $ServerName -Database Master -Query $query
$isCompatible = $isCompatible.Item(0)
if ($isCompatible -eq 'Yes' -and $InstallPy -eq 'Yes') {
Write-Host " This Version of SQL is Compatible with SQL Py "
Write-Host "This Version of SQL is Compatible with SQL Py "
## Create Py Database
Write-Host " Creating SQL Database for Py "
Write-Host "Creating SQL Database for Py "
Write-Host -ForeGroundColor 'cyan' (" Using $ServerName SQL Instance")
Write-Host ("Using $ServerName SQL Instance")
## Create PY Server DB
$dbName = $db + "_Py"
@ -77,208 +77,190 @@ if ($isCompatible -eq 'Yes' -and $InstallPy -eq 'Yes') {
$CreateSQLDB = "$ScriptPath\CreateDatabase.sql"
$CreateSQLObjects = "$ScriptPath\CreateSQLObjectsPy.sql"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the $dbName database")
Write-Host ("Calling Script to create the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLDB -serverinstance $ServerName -database master -Variable $SqlParameters
Write-Host -ForeGroundColor 'cyan' (" SQLServerDB $dbName Created")
Write-Host ("SQLServerDB $dbName Created")
invoke-sqlcmd "USE $dbName;"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the objects in the $dbName database")
Write-Host ("Calling Script to create the objects in the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLObjects -serverinstance $ServerName -database $dbName
Write-Host -ForeGroundColor 'cyan' (" SQLServerObjects Created in $dbName Database")
$OdbcName = "obdc" + $dbname
## Create ODBC Connection for PowerBI to Use
Add-OdbcDsn -Name $OdbcName -DriverName "ODBC Driver 13 for SQL Server" -DsnType 'System' -Platform '64-bit' -SetPropertyValue @("Server=$ServerName", "Trusted_Connection=Yes", "Database=$dbName") -ErrorAction SilentlyContinue -PassThru
Write-Host ("SQLServerObjects Created in $dbName Database")
$OdbcName = "obdc" + $dbname
## Create ODBC Connection for PowerBI to Use
Add-OdbcDsn -Name $OdbcName -DriverName "ODBC Driver 13 for SQL Server" -DsnType 'System' -Platform '64-bit' -SetPropertyValue @("Server=$ServerName", "Trusted_Connection=Yes", "Database=$dbName") -ErrorAction SilentlyContinue -PassThru
}
else
{
else {
if ($isCompatible -eq 'Yes' -and $InstallPy -eq 'Yes') {"This Version of SQL is not compatible with Py , Py Code and DB's will not be Created "}
else {" There is not a py version of this solution"}
else {Write-Host ("There is not a py version of this solution")}
}
If ($InstallR -eq 'Yes')
{
Write-Host " Creating SQL Database for R "
If ($InstallR -eq 'Yes') {
Write-Host ("Creating SQL Database for R")
Write-Host -ForeGroundColor 'cyan' (" Using $ServerName SQL Instance")
Write-Host (" Using $ServerName SQL Instance")
$dbName = $db + "_R"
$dbName = $db + "_R"
## Create RServer DB
$SqlParameters = @("dbName=$dbName")
## Create RServer DB
$SqlParameters = @("dbName=$dbName")
$CreateSQLDB = "$ScriptPath\CreateDatabase.sql"
$CreateSQLDB = "$ScriptPath\CreateDatabase.sql"
$CreateSQLObjects = "$ScriptPath\CreateSQLObjectsR.sql"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLDB -serverinstance $ServerName -database master -Variable $SqlParameters
$CreateSQLObjects = "$ScriptPath\CreateSQLObjectsR.sql"
Write-Host ("Calling Script to create the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLDB -serverinstance $ServerName -database master -Variable $SqlParameters
Write-Host -ForeGroundColor 'cyan' (" SQLServerDB $dbName Created")
invoke-sqlcmd "USE $dbName;"
Write-Host ("SQLServerDB $dbName Created")
invoke-sqlcmd "USE $dbName;"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the objects in the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLObjects -serverinstance $ServerName -database $dbName
Write-Host ("Calling Script to create the objects in the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLObjects -serverinstance $ServerName -database $dbName
Write-Host -ForeGroundColor 'cyan' (" SQLServerObjects Created in $dbName Database")
Write-Host ("SQLServerObjects Created in $dbName Database")
###Configure Database for R
Write-Host "
Configuring $SolutionName Solution for R
"
###Configure Database for R
Write-Host "Configuring $SolutionName Solution for R"
$dbName = $db + "_R"
$dbName = $db + "_R"
## Create ODBC Connection for PowerBI to Use
$OdbcName = "obdc" + $dbname
## Create ODBC Connection for PowerBI to Use
Add-OdbcDsn -Name $OdbcName -DriverName "ODBC Driver 13 for SQL Server" -DsnType 'System' -Platform '64-bit' -SetPropertyValue @("Server=$ServerName", "Trusted_Connection=Yes", "Database=$dbName") -ErrorAction SilentlyContinue -PassThru
## Create ODBC Connection for PowerBI to Use
$OdbcName = "obdc" + $dbname
## Create ODBC Connection for PowerBI to Use
Add-OdbcDsn -Name $OdbcName -DriverName "ODBC Driver 13 for SQL Server" -DsnType 'System' -Platform '64-bit' -SetPropertyValue @("Server=$ServerName", "Trusted_Connection=Yes", "Database=$dbName") -ErrorAction SilentlyContinue -PassThru
##########################################################################
# Deployment Pipeline
##########################################################################
##########################################################################
# Deployment Pipeline
##########################################################################
$RStart = Get-Date
try
{
$RStart = Get-Date
Write-Host -ForeGroundColor 'cyan' (" Import CSV File(s). This Should take about 30 Seconds Per File")
try {
Write-Host (" Import CSV File(s). This Should take about 30 Seconds Per File")
#$dataList = "LengthOfStay"
# upload csv files into SQL table
foreach ($dataFile in $dataList)
{
$destination = $solutionData + $dataFile +".csv"
$tableName = $dbName + ".dbo." + $dataFile
$tableSchema = $dataPath + $dataFile + ".xml"
bcp $tableName format nul -T -c -x -f $tableSchema -S $ServerName
bcp $tableName in $destination -T -S $ServerName -c -F2 -C "RAW" -b 50000 -t'|'
$qry = "BULK INSERT loan_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\loan_info_10k.txt'"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
Write-Host ("$datafile table loaded from CSV File(s).")
}
}
$qry = "BULK INSERT member_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\member_info_10k.txt'"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
catch {
Write-Host -ForegroundColor DarkYellow "Exception in populating database tables:"
Write-Host -ForegroundColor Red $Error[0].Exception
throw
}
Write-Host ("Finished loading .csv File(s).")
$qry = "BULK INSERT payments_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\payments_info_10k.txt'"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT loan_info_100k FROM 'C:\Solutions\LoanChargeOff\Data\loan_info_100k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT member_info_100k FROM 'C:\Solutions\LoanChargeOff\Data\member_info_100k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT payments_info_100k FROM 'C:\Solutions\LoanChargeOff\Data\payments_info_100k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# Write-Host ("Import CSV File(s). This Should take about 30 Seconds Per File")
Write-Host -ForeGroundColor 'cyan' (" Data has been Loaded from Csv Files")
# $qry = "BULK INSERT loan_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\loan_info_10k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT member_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\member_info_10k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT payments_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\payments_info_10k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# upload csv files into SQL tables
foreach ($dataFile in $dataList)
{
#$destination = $SolutionData + $dataFile + ".csv"
#$destination = "'"+ $SolutionData + $dataFile + ".txt'"
#$tableName = $DBName + ".dbo." + $dataFile
#$tableSchema = $dataPath + "\" + $dataFile + ".xml"
#$dataSet = Import-Csv $destination
#Write-Host -ForegroundColor 'cyan' (" Loading $dataFile.csv into SQL Table")
##Write-SqlTableData -InputData $dataSet -DatabaseName $dbName -Force -Passthru -SchemaName dbo -ServerInstance $ServerName -TableName $dataFile
##invoke-expression "bcp $dataFile in $destination -S $ServerName -d $dbName -T -k -c"
#invoke-expression "bcp $tableName in $destination -S $ServerName -f $tableSchema -F 2 -C "RAW" -b 100000 -T"
#$qry = "BULK INSERT $tableName FROM $destination"
#SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
#Write-Host -ForeGroundColor 'cyan' (" $datafile table loaded from CSV File(s).")
}
}
Write-Host ("Training Model and Scoring Data...")
catch
{
Write-Host -ForegroundColor DarkYellow "Exception in populating database tables:"
Write-Host -ForegroundColor Red $Error[0].Exception
throw
}
Write-Host -ForeGroundColor 'cyan' (" Finished loading .csv File(s).")
$query = "EXEC Initial_Run_Once_R"
#SqlServer\Invoke-Sqlcmd -ServerInstance $ServerName -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
Write-Host -ForeGroundColor 'Cyan' (" Training Model and Scoring Data...")
$Rend = Get-Date
$query = "EXEC Initial_Run_Once_R"
#SqlServer\Invoke-Sqlcmd -ServerInstance $ServerName -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
$Rend = Get-Date
$Duration = New-TimeSpan -Start $RStart -End $Rend
Write-Host -ForegroundColor 'green'(" R Server Configured in $Duration")
$Duration = New-TimeSpan -Start $RStart -End $Rend
Write-Host (" R Server Configured in $Duration")
}
ELSE
{Write-Host -ForegroundColor 'Green' "There is not a R Version for this Solution so R will not be Installed"}
{Write-Host ("There is not a R Version for this Solution so R will not be Installed")}
###Conifgure Database for Py
if ($isCompatible -eq 'Yes'-and $InstallPy -eq 'Yes')
{
$PyStart = get-date
Write-Host "
if ($isCompatible -eq 'Yes' -and $InstallPy -eq 'Yes') {
$PyStart = get-date
Write-Host "
Configuring $SolutionName Solution for Py
# "
$dbname = $db + "_Py"
$dbname = $db + "_Py"
##########################################################################
# Deployment Pipeline Py
##########################################################################
##########################################################################
# Deployment Pipeline Py
##########################################################################
try
{
try {
Write-Host -ForeGroundColor 'cyan' (" Import CSV File(s). This Should take about 30 Seconds Per File")
#$dataList = "LengthOfStay"
Write-Host (" Import CSV File(s). This Should take about 30 Seconds Per File")
#$dataList = "LengthOfStay"
# upload csv files into SQL tables
foreach ($dataFile in $dataList)
{
$destination = $SolutionData + $dataFile + ".csv"
$tableName = $DBName + ".dbo." + $dataFile
$tableSchema = $dataPath + "\" + $dataFile + ".xml"
$dataSet = Import-Csv $destination
Write-Host -ForegroundColor 'cyan' (" Loading $dataFile.csv into SQL Table")
Write-SqlTableData -InputData $dataSet -DatabaseName $dbName -Force -Passthru -SchemaName dbo -ServerInstance $ServerName -TableName $dataFile
# upload csv files into SQL table
foreach ($dataFile in $dataList)
{
$destination = $solutionData + $dataFile +".csv"
$tableName = $dbName + ".dbo." + $dataFile
$tableSchema = $dataPath + $dataFile + ".xml"
bcp $tableName format nul -T -c -x -f $tableSchema -S $ServerName
bcp $tableName in $destination -T -S $ServerName -c -F2 -C "RAW" -b 50000 -t'|'
Write-Host -ForeGroundColor 'cyan' (" $datafile table loaded from CSV File(s).")
}
}
catch
{
Write-Host -ForegroundColor DarkYellow "Exception in populating database tables:"
Write-Host -ForegroundColor Red $Error[0].Exception
throw
}
Write-Host -ForeGroundColor 'cyan' (" Finished loading .csv File(s).")
Write-Host -ForeGroundColor 'Cyan' (" Training Model and Scoring Data...")
$query = "EXEC Inital_Run_Once_Py"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
Write-Host ("$datafile table loaded from CSV File(s).")
}
}
catch {
Write-Host -ForegroundColor DarkYellow "Exception in populating database tables:"
Write-Host -ForegroundColor Red $Error[0].Exception
throw
}
Write-Host ("Finished loading .csv File(s).")
$Pyend = Get-Date
Write-Host ("Training Model and Scoring Data...")
$query = "EXEC Inital_Run_Once_Py"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
$Duration = New-TimeSpan -Start $PyStart -End $Pyend
Write-Host -ForegroundColor 'green'(" Py Server Configured in $Duration")
$Pyend = Get-Date
$Duration = New-TimeSpan -Start $PyStart -End $Pyend
Write-Host ("Py Server Configured in $Duration")
}

Двоичные данные
Resources/ActionScripts/CreateSQLObjectsR.sql

Двоичный файл не отображается.

Просмотреть файл

@ -2,185 +2,178 @@
[CmdletBinding()]
param(
[parameter(Mandatory=$false, Position=1)]
[ValidateNotNullOrEmpty()]
[string]$serverName,
[parameter(Mandatory = $false, Position = 1)]
[ValidateNotNullOrEmpty()]
[string]$serverName,
[parameter(Mandatory=$false, Position=2)]
[ValidateNotNullOrEmpty()]
[string]$baseurl,
[parameter(Mandatory = $false, Position = 2)]
[ValidateNotNullOrEmpty()]
[string]$baseurl,
[parameter(Mandatory=$True, Position=3)]
[ValidateNotNullOrEmpty()]
[string]$username,
[parameter(Mandatory = $false, Position = 3)]
[ValidateNotNullOrEmpty()]
[string]$username,
[parameter(Mandatory=$True, Position=4)]
[ValidateNotNullOrEmpty()]
[string]$password,
[parameter(Mandatory = $false, Position = 4)]
[ValidateNotNullOrEmpty()]
[string]$password,
[parameter(Mandatory=$false, Position=5)]
[ValidateNotNullOrEmpty()]
[string]$Prompt
[parameter(Mandatory = $false, Position = 5)]
[ValidateNotNullOrEmpty()]
[string]$Prompt
)
#################################################################
##DSVM Does not have SQLServer Powershell Module Install or Update
#################################################################
###Check to see if user is Admin
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")
if ($isAdmin -eq 'True') {
#################################################################
##DSVM Does not have SQLServer Powershell Module Install or Update
#################################################################
Write-Host "Installing SQLServer Power Shell Module or Updating to latest "
Write-Host "Installing SQLServer Power Shell Module or Updating to latest "
if (Get-Module -ListAvailable -Name SQLServer)
if (Get-Module -ListAvailable -Name SQLServer)
{Update-Module -Name "SQLServer" -MaximumVersion 21.0.17199}
Else
Else
{Install-Module -Name SqlServer -RequiredVersion 21.0.17199 -Scope AllUsers -AllowClobber -Force}
#Set-PSRepository -Name PSGallery -InstallationPolicy Untrusted
#Set-PSRepository -Name PSGallery -InstallationPolicy Untrusted
Import-Module -Name SqlServer -MaximumVersion 21.0.17199 -Force
#$Prompt= if ($Prompt -match '^y(es)?$') {'Y'} else {'N'}
$Prompt = 'N'
# if($baseurl::IsNullOrEmpty) {$isStandalone = 'Y'} ELSE {$isStandalone = 'N'}
# write-host $baseurl
# #$isStandAlone = 'N'
##Change Values here for Different Solutions
$SolutionName = "LoanChargeOff"
$SolutionFullName = "r-server-loan-chargeoff"
$JupyterNotebook = "LoanChargeOff.ipynb"
$Shortcut = "LoanChargeOffHelp.url"
### DON'T FORGET TO CHANGE TO MASTER LATER...
$Branch = "master"
$InstallR = 'Yes' ## If Solution has a R Version this should be 'Yes' Else 'No'
$InstallPy = 'No' ## If Solution has a Py Version this should be 'Yes' Else 'No'
$SampleWeb = 'No' ## If Solution has a Sample Website this should be 'Yes' Else 'No'
$EnableFileStream = 'No' ## If Solution Requires FileStream DB this should be 'Yes' Else 'No'
$isMixedMode = 'No' ## If Solution Requires SQL Mixed Mode Authentication this should be 'Yes' Else 'No'
$Prompt = 'N'
$setupLog = "c:\tmp\setup_log.txt"
Start-Transcript -Path $setupLog -Append
$startTime = Get-Date
Write-Host "Start time:" $startTime
Write-Host "ServerName set to $ServerName"
###These probably don't need to change , but make sure files are placed in the correct directory structure
$solutionTemplateName = "Solutions"
$solutionTemplatePath = "C:\" + $solutionTemplateName
$checkoutDir = $SolutionName
$SolutionPath = $solutionTemplatePath + '\' + $checkoutDir
$desktop = "C:\Users\Public\Desktop\"
$scriptPath = $SolutionPath + "\Resources\ActionScripts\"
$SolutionData = $SolutionPath + "\Data\"
##########################################################################
#Clone Data from GIT
##########################################################################
#$Prompt= if ($Prompt -match '^y(es)?$') {'Y'} else {'N'}
$Prompt = 'N'
$clone = "git clone --branch $Branch --single-branch https://github.com/Microsoft/$SolutionFullName $solutionPath"
# if($baseurl::IsNullOrEmpty) {$isStandalone = 'Y'} ELSE {$isStandalone = 'N'}
# write-host $baseurl
# #$isStandAlone = 'N'
if (Test-Path $SolutionPath) { Write-Host " Solution has already been cloned"}
ELSE {Invoke-Expression $clone}
##Change Values here for Different Solutions
$SolutionName = "LoanChargeOff"
$SolutionFullName = "r-server-loan-chargeoff"
$JupyterNotebook = "LoanChargeOff.ipynb"
$Shortcut = "LoanChargeOffHelp.url"
### DON'T FORGET TO CHANGE TO MASTER LATER...
$Branch = "master"
$InstallR = 'Yes' ## If Solution has a R Version this should be 'Yes' Else 'No'
$InstallPy = 'No' ## If Solution has a Py Version this should be 'Yes' Else 'No'
$SampleWeb = 'No' ## If Solution has a Sample Website this should be 'Yes' Else 'No'
$EnableFileStream = 'No' ## If Solution Requires FileStream DB this should be 'Yes' Else 'No'
$Prompt = 'N'
$setupLog = "c:\tmp\setup_log.txt"
Start-Transcript -Path $setupLog -Append
$startTime = Get-Date
Write-Host "Start time:" $startTime
Write-Host "ServerName set to $ServerName"
###These probably don't need to change , but make sure files are placed in the correct directory structure
$solutionTemplateName = "Solutions"
$solutionTemplatePath = "C:\" + $solutionTemplateName
$checkoutDir = $SolutionName
$SolutionPath = $solutionTemplatePath + '\' + $checkoutDir
$desktop = "C:\Users\Public\Desktop\"
$scriptPath = $SolutionPath + "\Resources\ActionScripts\"
$SolutionData = $SolutionPath + "\Data\"
##########################################################################
#Clone Data from GIT
##########################################################################
$clone = "git clone --branch $Branch --single-branch https://github.com/Microsoft/$SolutionFullName $solutionPath"
if (Test-Path $SolutionPath) { Write-Host " Solution has already been cloned"}
ELSE {Invoke-Expression $clone}
If ($InstalR -eq 'Yes')
{
Write-Host "Installing R Packages"
Set-Location "C:\Solutions\$SolutionName\Resources\ActionScripts\"
# install R Packages
Rscript install.R
}
Write-Host $baseurl
#if(!$baseurl::IsNullOrEmpty)
if($baseurl)
{
cd $SolutionData
# List of data files to be downloaded
$dataList = "loan_info_10k", "member_info_10k", "payments_info_10k", "loan_info_100k", "member_info_100k", "payments_info_100k", "loan_info_1m", "member_info_1m", "payments_info_1m"
#$dataList = "loan_info_10k", "member_info_10k", "payments_info_10k", "loan_info_100k", "member_info_100k", "payments_info_100k"
$dataExtn = ".csv"
$hashExtn = ".hash"
foreach ($dataFile in $dataList)
{
$down = $baseurl + '/' + $dataFile + $dataExtn
Write-Host -ForeGroundColor 'magenta' "Downloading file $down..."
Start-BitsTransfer -Source $down
}
}
## if FileStreamDB is Required Alter Firewall ports for 139 and 445
if ($EnableFileStream -eq 'Yes')
{
netsh advfirewall firewall add rule name="Open Port 139" dir=in action=allow protocol=TCP localport=139
netsh advfirewall firewall add rule name="Open Port 445" dir=in action=allow protocol=TCP localport=445
Write-Host "Firewall as been opened for filestream access..."
}
If ($EnableFileStream -eq 'Yes')
{
Set-Location "C:\Program Files\Microsoft\ML Server\PYTHON_SERVER\python.exe"
.\setup.py install
Write-Host "Py Instal has been updated to latest version..."
If ($InstalR -eq 'Yes') {
Write-Host "Installing R Packages"
Set-Location "C:\Solutions\$SolutionName\Resources\ActionScripts\"
# install R Packages
Rscript install.R
}
############################################################################################
#Configure SQL to Run our Solutions
############################################################################################
$Query = "SELECT SERVERPROPERTY('ServerName')"
$si = invoke-sqlcmd -Query $Query
$si = $si.Item(0)
$serverName = if([string]::IsNullOrEmpty($servername)) {$si}
### Change Authentication From Windows Auth to Mixed Mode
Invoke-Sqlcmd -Query "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2;" -ServerInstance "LocalHost"
$Query = "CREATE LOGIN $username WITH PASSWORD=N'$password', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
$Query = "ALTER SERVER ROLE [sysadmin] ADD MEMBER $username"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
Write-Host "Configuring SQL to allow running of External Scripts "
### Allow Running of External Scripts , this is to allow R Services to Connect to SQL
Invoke-Sqlcmd -Query "EXEC sp_configure 'external scripts enabled', 1"
### Force Change in SQL Policy on External Scripts
Invoke-Sqlcmd -Query "RECONFIGURE WITH OVERRIDE"
Write-Host "SQL Server Configured to allow running of External Scripts "
### Enable FileStreamDB if Required by Solution
if ($EnableFileStream -eq 'Yes')
#if(!$baseurl::IsNullOrEmpty)
if ($baseurl)
{
# Enable FILESTREAM
Set-Location $SolutionData
# List of data files to be downloaded
$dataList = "loan_info_100k", "member_info_100k", "payments_info_100k", "loan_info_1m", "member_info_1m", "payments_info_1m"
$dataExtn = ".csv"
foreach ($dataFile in $dataList) {
$down = $baseurl + '/' + $dataFile + $dataExtn
Write-Host "Downloading file $down..."
Start-BitsTransfer -Source $down
}
}
## if FileStreamDB is Required Alter Firewall ports for 139 and 445
if ($EnableFileStream -eq 'Yes') {
netsh advfirewall firewall add rule name="Open Port 139" dir=in action=allow protocol=TCP localport=139
netsh advfirewall firewall add rule name="Open Port 445" dir=in action=allow protocol=TCP localport=445
Write-Host "Firewall as been opened for filestream access..."
}
If ($EnableFileStream -eq 'Yes') {
Set-Location "C:\Program Files\Microsoft\ML Server\PYTHON_SERVER\python.exe"
.\setup.py install
Write-Host "Py Instal has been updated to latest version..."
}
############################################################################################
#Configure SQL to Run our Solutions
############################################################################################
$Query = "SELECT SERVERPROPERTY('ServerName')"
$si = invoke-sqlcmd -Query $Query
$si = $si.Item(0)
$serverName = if ([string]::IsNullOrEmpty($servername)) {$si}
if ($isMixedMode -eq 'Yes') {
### Change Authentication From Windows Auth to Mixed Mode
Invoke-Sqlcmd -Query "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2;" -ServerInstance "LocalHost"
$Query = "CREATE LOGIN $username WITH PASSWORD=N'$password', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
$Query = "ALTER SERVER ROLE [sysadmin] ADD MEMBER $username"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
Write-Host "SQL Server Authentication switched to mixed mode"
}
Write-Host "Configuring SQL to allow running of External Scripts "
### Allow Running of External Scripts , this is to allow R Services to Connect to SQL
Invoke-Sqlcmd -Query "EXEC sp_configure 'external scripts enabled', 1"
### Force Change in SQL Policy on External Scripts
Invoke-Sqlcmd -Query "RECONFIGURE WITH OVERRIDE"
Write-Host "SQL Server Configured to allow running of External Scripts "
### Enable FileStreamDB if Required by Solution
if ($EnableFileStream -eq 'Yes') {
# Enable FILESTREAM
$instance = "MSSQLSERVER"
$wmi = Get-WmiObject -Namespace "ROOT\Microsoft\SqlServer\ComputerManagement14" -Class FilestreamSettings | where-object {$_.InstanceName -eq $instance}
$wmi.EnableFilestream(3, $instance)
@ -194,106 +187,90 @@ if ($EnableFileStream -eq 'Yes')
Stop-Service "MSSQ*"
Start-Service "MSSQ*"
}
ELSE {
Write-Host "Restarting SQL Services "
### Changes Above Require Services to be cycled to take effect
### Stop the SQL Service and Launchpad wild cards are used to account for named instances
Restart-Service -Name "MSSQ*" -Force
}
##Unzip Data Files
#Expand-Archive -LiteralPath "$SolutionData\10kRecords.zip" -DestinationPath $SolutionData -Force
####Run Configure SQL to Create Databases and Populate with needed Data
$ConfigureSql = "C:\Solutions\$SolutionName\Resources\ActionScripts\ConfigureSQL.ps1 $ServerName $SolutionName $InstallPy $InstallR $Prompt"
Invoke-Expression $ConfigureSQL
Write-Host "Done with configuration changes to SQL Server"
Write-Host (" Installing latest Power BI...")
# Download PowerBI Desktop installer
Start-BitsTransfer -Source "https://go.microsoft.com/fwlink/?LinkId=521662&clcid=0x409" -Destination powerbi-desktop.msi
# Silently install PowerBI Desktop
msiexec.exe /i powerbi-desktop.msi /qn /norestart ACCEPT_EULA=1
if (!$?) {
Write-Host -ForeGroundColor Red " Error installing Power BI Desktop. Please install latest Power BI manually."
}
##Create Shortcuts and Autostart Help File
Copy-Item "$ScriptPath\$Shortcut" C:\Users\Public\Desktop\
Copy-Item "$ScriptPath\$Shortcut" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\"
Write-Host "Help Files Copied to Desktop"
$WsShell = New-Object -ComObject WScript.Shell
$shortcut = $WsShell.CreateShortcut($desktop + $checkoutDir + ".lnk")
$shortcut.TargetPath = $solutionPath
$shortcut.Save()
# install modules for sample website
if ($SampleWeb -eq "Yes") {
if($SampleWeb -eq "Yes")
{
cd $SolutionPath\Website\
npm install
(Get-Content $SolutionPath\Website\server.js).replace('XXYOURSQLPW', $password) | Set-Content $SolutionPath\Website\server.js
(Get-Content $SolutionPath\Website\server.js).replace('XXYOURSQLUSER', $username) | Set-Content $SolutionPath\Website\server.js
}
}
$endTime = Get-Date
Write-Host ("$SolutionFullName Workflow Finished Successfully! You can close the PowerShell window.")
$Duration = New-TimeSpan -Start $StartTime -End $EndTime
Write-Host ("Total Deployment Time = $Duration")
Stop-Transcript
##Launch HelpURL
Start-Process "https://microsoft.github.io/$SolutionFullName/Typical.html"
## Close Powershell if not run on
if ($baseurl)
{Exit-PSHostProcess
EXIT}
}
ELSE
{
Write-Host "Restarting SQL Services "
### Changes Above Require Services to be cycled to take effect
### Stop the SQL Service and Launchpad wild cards are used to account for named instances
Restart-Service -Name "MSSQ*" -Force
}
### Start the SQL Service
#Start-Service -Name "MSSQ*"
#Write-Host -ForegroundColor 'Cyan' " SQL Services Restarted"
##Unzip Data Files
#Expand-Archive -LiteralPath "$SolutionData\10kRecords.zip" -DestinationPath $SolutionData -Force
####Run Configure SQL to Create Databases and Populate with needed Data
$ConfigureSql = "C:\Solutions\$SolutionName\Resources\ActionScripts\ConfigureSQL.ps1 $ServerName $SolutionName $InstallPy $InstallR $Prompt"
Invoke-Expression $ConfigureSQL
Write-Host "Done with configuration changes to SQL Server"
Write-Host -ForeGroundColor cyan " Installing latest Power BI..."
# Download PowerBI Desktop installer
Start-BitsTransfer -Source "https://go.microsoft.com/fwlink/?LinkId=521662&clcid=0x409" -Destination powerbi-desktop.msi
# Silently install PowerBI Desktop
msiexec.exe /i powerbi-desktop.msi /qn /norestart ACCEPT_EULA=1
if (!$?) {
Write-Host -ForeGroundColor Red " Error installing Power BI Desktop. Please install latest Power BI manually."
}
##Create Shortcuts and Autostart Help File
Copy-Item "$ScriptPath\$Shortcut" C:\Users\Public\Desktop\
Copy-Item "$ScriptPath\$Shortcut" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\"
Write-Host "Help Files Copied to Desktop"
$WsShell = New-Object -ComObject WScript.Shell
$shortcut = $WsShell.CreateShortcut($desktop + $checkoutDir + ".lnk")
$shortcut.TargetPath = $solutionPath
$shortcut.Save()
## copy Jupyter Notebook files
# Move-Item $SolutionPath\R\$JupyterNotebook c:\tmp\
# sed -i "s/XXYOURSQLPW/$password/g" c:\tmp\$JupyterNotebook
# sed -i "s/XXYOURSQLUSER/$username/g" c:\tmp\$JupyterNotebook
# Move-Item c:\tmp\$JupyterNotebook $SolutionPath\R\
#cp $SolutionData*.csv c:\dsvm\notebooks
# substitute real username and password in notebook file
#XXXXXXXXXXChange to NEw NotebookNameXXXXXXXXXXXXXXXXXX#
if ($InstallPy -eq "Yes")
{
# Move-Item $SolutionPath\Python\$JupyterNotebook c:\tmp\
# sed -i "s/XXYOURSQLPW/$password/g" c:\tmp\$JupyterNotebook
# sed -i "s/XXYOURSQLUSER/$username/g" c:\tmp\$JupyterNotebook
# Move-Item c:\tmp\$JupyterNotebook $SolutionPath\Python\
}
# install modules for sample website
if($SampleWeb -eq "Yes")
{
cd $SolutionPath\Website\
npm install
Move-Item $SolutionPath\Website\server.js c:\tmp\
sed -i "s/XXYOURSQLPW/$password/g" c:\tmp\server.js
sed -i "s/XXYOURSQLUSER/$username/g" c:\tmp\server.js
Move-Item c:\tmp\server.js $SolutionPath\Website
}
$endTime = Get-Date
Write-Host ("$SolutionFullName Workflow Finished Successfully!")
$Duration = New-TimeSpan -Start $StartTime -End $EndTime
Write-Host ("Total Deployment Time = $Duration")
Stop-Transcript
##Launch HelpURL
Start-Process "https://microsoft.github.io/$SolutionFullName/Typical.html"
Write-Host "To install this Solution you need to run Powershell as an Administrator. This program will close automatically in 20 seconds"
Start-Sleep -s 20
## Close Powershell
Exit-PSHostProcess
EXIT
EXIT }