Skip to content

Commit

Permalink
Merge pull request #92 from Green-Software-Foundation/91-passing-expe…
Browse files Browse the repository at this point in the history
…cted-lifespan-of-server-in-boavizta-api-for-getting-embodied-emission

91 passing expected lifespan of server in boavizta api for getting embodied emission
  • Loading branch information
gnanakeethan authored Aug 28, 2023
2 parents 5c4cb1d + 7706abd commit 0fe293f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/lib/boavizta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ describe('cpu:initialize with params', () => {
},
])
).resolves.toStrictEqual([
{m: 0.905, e: 0.25},
{m: 0.00377, e: 0.0007702777777777777},
{m: 0.00377, e: 0.000439},
{m: 0.00377, e: 0.0014238333333333332},
{m: 0.678, e: 0.25},
{m: 0.00283, e: 0.0007702777777777777},
{m: 0.00283, e: 0.000439},
{m: 0.00283, e: 0.0014238333333333332},
]);
});
});
Expand Down Expand Up @@ -139,10 +139,10 @@ describe('cloud:initialize with params', () => {
},
])
).resolves.toStrictEqual([
{m: 0.008, e: 0.00008374722222222223},
{m: 0.008, e: 0.00006074166666666666},
{m: 0.008, e: 0.00004233888888888889},
{m: 0.008, e: 0.00011007222222222222},
{m: 0.004, e: 0.00008374722222222223},
{m: 0.004, e: 0.00006074166666666666},
{m: 0.004, e: 0.00004233888888888889},
{m: 0.004, e: 0.00011007222222222222},
]);
});

Expand Down
15 changes: 14 additions & 1 deletion src/lib/boavizta.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import axios from 'axios';

import {IImpactModelInterface} from './interfaces';
export {IImpactModelInterface} from './interfaces';
import {CONFIG} from '../config';

import {
BoaviztaInstanceTypes,
IBoaviztaUsageSCI,
KeyValuePair,
} from '../types/boavizta';

export {IImpactModelInterface} from './interfaces';

export {
BoaviztaInstanceTypes,
IBoaviztaUsageSCI,
Expand All @@ -23,6 +25,7 @@ abstract class BoaviztaImpactModel implements IImpactModelInterface {
name: string | undefined;
sharedParams: object | undefined = undefined;
metricType: 'cpu' | 'gpu' | 'ram' = 'cpu';
expectedLifespan = 4;

authenticate(authParams: object) {
this.authCredentials = authParams;
Expand Down Expand Up @@ -86,6 +89,9 @@ abstract class BoaviztaImpactModel implements IImpactModelInterface {
hours_use_time: duration / 3600.0,
time_workload: metric * 100.0,
};
if (typeof this.expectedLifespan === 'number') {
usageInput['years_life_time'] = this.expectedLifespan;
}
usageInput = this.addLocationToUsage(usageInput);

return usageInput;
Expand Down Expand Up @@ -171,6 +177,9 @@ export class BoaviztaCpuImpactModel
throw new Error('Improper configure: Missing core_units parameter');
}

if ('expected_lifespan' in staticParams) {
this.expectedLifespan = staticParams.expected_lifespan as number;
}
this.sharedParams = Object.assign({}, staticParams);

return this.sharedParams;
Expand Down Expand Up @@ -217,6 +226,10 @@ export class BoaviztaCloudImpactModel
await this.validateInstanceType(staticParams);
// if no valid location found, throw error
await this.validateLocation(staticParams);
if ('expected_lifespan' in staticParams) {
this.expectedLifespan = staticParams.expected_lifespan as number;
}

this.sharedParams = Object.assign({}, staticParams);

return this.sharedParams;
Expand Down

0 comments on commit 0fe293f

Please sign in to comment.