aboutsummaryrefslogtreecommitdiffstats
path: root/so-simulator/src/main/java/org/onap/so/simulator/scenarios/openstack/CreateAAInventory.java
blob: aa54a7a996aa1bd6e9d58231d1146fcd70143b35 (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
34
35
36
37
38
39
40
41
42
43
package org.onap.so.simulator.scenarios.openstack;

import java.io.InputStream;
import org.onap.aai.domain.yang.Vserver;
import org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import com.consol.citrus.actions.AbstractTestAction;
import com.consol.citrus.context.TestContext;

public class CreateAAInventory extends AbstractTestAction {

    @Override
    public void doExecute(TestContext context) {
        final Logger logger = LoggerFactory.getLogger(CreateAAInventory.class);

        try {
            String stackName = context.getVariable("stackName");

            if (stackName != null && stackName.equals("replace_module")) {
                String vServerId = "92272b67-d23f-42ca-87fa-7b06a9ec81f3";
                AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
                AAICommonObjectMapperProvider aaiMapper = new AAICommonObjectMapperProvider();
                InputStream vserverFile =
                        new ClassPathResource("openstack/gr_api/CreateAAIInventory.json").getInputStream();
                Vserver vserver = aaiMapper.getMapper().readValue(vserverFile, Vserver.class);
                AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(
                        AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("cloudOwner", "regionOne")
                                .tenant("0422ffb57ba042c0800a29dc85ca70f8").vserver(vServerId));
                aaiResourceClient.create(vserverURI, vserver);
            }
        } catch (Exception e) {
            logger.debug("Exception in CreateAAInventory.doExecute", e);
        }

    }

}