summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/assets/styles/images/canvas-tagging-icons/adding_policy.svg
blob: 217d92c65491b0c1c663a6cef1a7bc020bafe551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?xml version="1.0" encoding="UTF-8"?>
<svg width="28px" height="28px" viewBox="0 0 28 28" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 48.2 (47327) - http://www.bohemiancoding.com/sketch -->
    <title>Group 12 Copy</title>
    <desc>Created with Sketch.</desc>
    <defs>
        <filter x="-22.7%" y="-13.6%" width="145.5%" height="145.5%" filterUnits="objectBoundingBox" id="filter-1">
            <feOffset dx="0" dy="2" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
            <feGaussianBlur stdDeviation="1" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1" result="shadowMatrixOuter1"></feColorMatrix>
            <feMerge>
                <feMergeNode in="shadowMatrixOuter1"></feMergeNode>
                <feMergeNode in="SourceGraphic"></feMergeNode>
            </feMerge>
        </filter>
        <path d="M6,4 L6,1 C6,0.4 5.6,0 5,0 C4.4,0 4,0.4 4,1 L4,4 L1,4 C0.4,4 0,4.4 0,5 C0,5.6 0.4,6 1,6 L4,6 L4,9 C4,9.6 4.4,10 5,10 C5.6,10 6,9.6 6,9 L6,6 L9,6 C9.6,6 10,5.6 10,5 C10,4.4 9.6,4 9,4 L6,4 Z" id="path-2"></path>
    </defs>
    <g id="sdc" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="Group-12-Copy" transform="translate(3.000000, 1.000000)">
            <g id="Group-4-Copy" filter="url(#filter-1)" fill="#0568AE" stroke="#FFFFFF">
                <g id="Group-3">
                    <path d="M3,0 L19,0 C20.6568542,-3.04359188e-16 22,1.34314575 22,3 L22,19 C22,20.6568542 20.6568542,22 19,22 L3,22 C1.34314575,22 2.02906125e-16,20.6568542 0,19 L0,3 C-2.02906125e-16,1.34314575 1.34314575,3.04359188e-16 3,0 Z" id="Rectangle-15-Copy-5"></path>
                </g>
            </g>
            <g id="color-/-gray-#5A5A5A-/-idle--Copy-34" transform="translate(6.000000, 6.000000)">
                <mask id="mask-3" fill="white">
                    <use xlink:href="#path-2"></use>
                </mask>
                <use id="Mask" fill="#FFFFFF" xlink:href="#path-2"></use>
            </g>
        </g>
    </g>
</svg>
or: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
import { HttpClient } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core';
import { tap } from 'rxjs/operators';
import { Distribution } from '../../../../models/distribution';
import { ISdcConfig, SdcConfigToken } from '../../../config/sdc-config.config';

@Injectable()
export class DistributionService {
    protected baseUrl;
    private distributionList = [];
    private distributionStatusesMap = {};

    // tslint:disable:no-string-literal

    constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
        this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
    }

    // Once the distribution page is loaded or when the user wants to refresh the list
     async initDistributionsList(componentUuid: string): Promise<object> {
        const distributionsListURL = this.baseUrl + 'services/' + componentUuid + '/distribution';
        const res = this.http.get<Distribution[]>(distributionsListURL).pipe(tap( (result) => {
            this.distributionList = result['distributionStatusOfServiceList'];
            this.insertDistrbutionsToMap();
        }  ));
        return res.toPromise();
    }

    // Once the user click on the relevant distribution ID in the distribution table (open and close)
    async initDistributionsStatusForDistributionID(distributionID: string): Promise<object> {
        const distributionStatus = this.baseUrl + 'services/distribution/' + distributionID;
        const res = this.http.get<object>(distributionStatus).pipe(tap( (result) => {
            this.insertDistributionStatusToDistributionsMap(distributionID, result['distributionStatusList']);
        }  ));
        return res.toPromise();
    }

    public getDistributionList(specificDistributionID?: string) {
        if (specificDistributionID) {
            return this.distributionList.filter((distribution) => {
                return distribution['distributionID'] === specificDistributionID;
            });
        } else {
            return this.distributionList;
        }
    }

    public getComponentsByDistributionID(distributionID: string) {
        const components = [];
        const distributionStatusMap = this.getStatusMapForDistributionID(distributionID);
        if (distributionStatusMap) {
            distributionStatusMap.forEach((component) => components.push(component.componentID));
        }
        return components;
    }

    // get array of artifacts per distributionID w/o componentName, sliced by artifact status
    public getArtifactsForDistributionIDAndComponentByStatus(distributionID: string, statusToSearch: string, componentName?: string) {
        const filteredArtifactsByStatus = [];

        if (componentName) {
            this.getArtifactstByDistributionIDAndComponentsName(distributionID, componentName).forEach ( (artifact) => {
                if (this.artifactStatusHasMatch(artifact, statusToSearch)) {
                    filteredArtifactsByStatus.push(artifact);
                }
            } );
        } else {
            this.getArtifactstByDistributionIDAndComponentsName(distributionID).forEach ( (artifact) => {
                if (this.artifactStatusHasMatch(artifact, statusToSearch)) {
                    filteredArtifactsByStatus.push(artifact);
                }
            } );
        }
        return filteredArtifactsByStatus;
    }

    public getArtifactstByDistributionIDAndComponentsName(distributionID: string, componentName?: string): any[] {
        const artifacts = [];
        if (this.getStatusMapForDistributionID(distributionID)) {
            if (componentName) {
                if (this.getStatusMapForDistributionID(distributionID).filter((component) => component.componentID === componentName).length > 0) {
                    const artifactsArr = this.getStatusMapForDistributionID(distributionID).filter((component) => component.componentID === componentName)[0]['artifacts']
                    if (artifactsArr.length > 0) {
                        artifactsArr.forEach((artifact) => {
                            const artifactObj = {
                                url: artifact.artifactUrl,
                                name: artifact.artifactName,
                                statuses: artifact.statuses
                            };
                            artifacts.push(artifactObj);
                        });
                    }
                }
            } else {
                const components = this.getComponentsByDistributionID(distributionID);
                components.forEach((componentName) => {
                    if (this.getStatusMapForDistributionID(distributionID).filter((component) => component.componentID === componentName).length > 0) {
                        const artifactsArr = this.getStatusMapForDistributionID(distributionID).filter((component) => component.componentID === componentName)[0]['artifacts']
                        if (artifactsArr.length > 0) {
                            artifactsArr.forEach((artifact) => {
                                const artifactObj = {
                                    url: artifact.artifactUrl,
                                    name: artifact.artifactName,
                                    statuses: artifact.statuses,
                                    errorReason: artifact.errorReason
                                };
                                artifacts.push(artifactObj);
                            });
                        }
                    }
                });
            }
        }
        return artifacts;
    }

    public getStatusMapForDistributionID(distributionID: string) {
        return this.distributionStatusesMap[distributionID];
    }

    public markDeploy(uniqueId: string, distributionID: string): Promise<object> {
        const distributionStatus = this.baseUrl + 'services/' + uniqueId + '/distribution/' + distributionID + '/markDeployed';
        const res = this.http.post<object>(distributionStatus, {}).pipe(tap( (result) => {
            console.log(result);
        }  ));
        return res.toPromise();
    }

    public getMSOStatus(distributionID: string, componentName: string): string {
        const msoStatus = this.distributionStatusesMap[distributionID].filter((component) => component.componentID === componentName)[0].msoStatus;
        return msoStatus ? msoStatus : '';
    }

    private artifactStatusHasMatch(artifact: any, statusToSerach: string) {
        for (let i = 0; i < artifact.statuses.length; i++) {
            if (artifact.statuses[i].status === statusToSerach) {
                return true;
            }
        }
        return false;
    }

    private insertDistributionStatusToDistributionsMap(distributionID: string, distributionStatusMapResponseFromServer: object[]) {

        // // Clear the Distribution ID array - to avoid statuses duplications
        const distribution = this.distributionStatusesMap[distributionID];
        distribution.length = 0;

        // Sort the response of statuses from Server, so it will be easy to pop the latest status when it will be required
        const sortedResponseByTimeStamp = distributionStatusMapResponseFromServer.sort((a, b) => b['timestamp'] - a['timestamp'])

        sortedResponseByTimeStamp.map((distributionStatus) => {
            const formattedDate = this.formatDate(distributionStatus['timestamp']);

            // if (distributionStatus['url'] === null) {
            //     distributionStatus['url'] = "";
            // }

            const detailedArtifactStatus = {
                componentID: distributionStatus['omfComponentID'],
                artifactName: distributionStatus['url']? distributionStatus['url'].split('/').pop() : '',
                url: distributionStatus['url'],
                time: distributionStatus['timestamp'],
                status: distributionStatus['status'],
                errorReason: distributionStatus['errorReason']
            };



            // Add Component to this.distributionStatusesMap in case not exist.
            let componentPosition = _.findIndex(distribution, {componentID: detailedArtifactStatus.componentID})

            if (componentPosition === -1) {
                this.addComponentIdToDistributionStatusMap(distributionID, detailedArtifactStatus.componentID);
                componentPosition = distribution.length - 1;
            }

            const component = distribution[componentPosition];


            // Add Artifact to this.distributionStatusesMap[componentID] in case not exist.
            let artifactPosition = _.findIndex(component.artifacts, {artifactUrl: detailedArtifactStatus.url})

            if (artifactPosition === -1) {
                this.addArtifactToComponentId(distributionID, componentPosition, detailedArtifactStatus.artifactName, detailedArtifactStatus.url);
                artifactPosition = component.artifacts.length - 1;
            }


            // Add status to relevat artifact in relevent componentID.
            if (detailedArtifactStatus.url) {
                // Case where there is a url -> should add its status
                component.artifacts[artifactPosition].statuses.push({
                    timeStamp: detailedArtifactStatus.time,
                    status: detailedArtifactStatus.status,
                    errorReason: detailedArtifactStatus.errorReason
                });
            } else {
                // Should update the Component -> status from MSO
                this.distributionStatusesMap[distributionID][componentPosition].msoStatus = detailedArtifactStatus.status;
            }


        });
    }

    private addComponentIdToDistributionStatusMap(distributionID: string, componentIDValue: string) {
        this.distributionStatusesMap[distributionID].push({
            componentID: componentIDValue,
            msoStatus: null,
            artifacts: []
            });
    }

    private addArtifactToComponentId(distributionID: string, componentPosition: number, artifactNameValue: string, artifactURLValue: any) {
        if (artifactNameValue) {
            this.distributionStatusesMap[distributionID][componentPosition].artifacts.push({
                artifactName: artifactNameValue,
                artifactUrl: artifactURLValue,
                statuses: []
            });
        }
    }

    private insertDistrbutionsToMap() {
        this.distributionList.map((distribution) => this.distributionStatusesMap[distribution.distributionID] = []);
    }

    private formatDate(epochTime: string) {
        const intEpochTime = new Date(parseInt(epochTime, 10));
        const amOrPm = (intEpochTime.getHours() + 24) % 24 > 12 ? 'PM' : 'AM';
        const formattedDate = (intEpochTime.getMonth() + 1) + '/' + intEpochTime.getDate() + '/' +  intEpochTime.getFullYear() + ' ' + intEpochTime.getHours() + ':' +
            intEpochTime.getMinutes() + amOrPm;
        return formattedDate;
    }
}