Search in sources :

Example 46 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class ApiTestVcenter method createDefaultVcenterNoCleanUpRegister.

private URI createDefaultVcenterNoCleanUpRegister(BalancedWebResource user, int expectedStatus, boolean discoverVcenter, boolean cascadeTenancy) {
    VcenterCreateParam param = new VcenterCreateParam();
    param.setName(getDefaultVcenterName());
    param.setIpAddress(getDefaultVcenterIp());
    param.setUserName(getDefaultVcenterUser());
    param.setPassword(getDefaultVcenterPassword());
    param.setUseSsl(true);
    param.setPortNumber(VCENTER_PORT);
    param.setCascadeTenancy(cascadeTenancy);
    ClientResponse clientResponse = user.path(getVcenterApi()).queryParam(getDiscoverVcenterQueryParam(), new Boolean(discoverVcenter).toString()).post(ClientResponse.class, param);
    Assert.assertEquals(expectedStatus, clientResponse.getStatus());
    if (expectedStatus != HttpStatus.SC_OK && expectedStatus != HttpStatus.SC_ACCEPTED) {
        return NullColumnValueGetter.getNullURI();
    }
    TaskResourceRep taskResourceRep = clientResponse.getEntity(TaskResourceRep.class);
    Assert.assertNotNull(taskResourceRep.getResource().getId());
    while (taskResourceRep.getState().equalsIgnoreCase(TASK_STATUS_PENDING)) {
        clientResponse = user.path(getVdcTaskApi() + "/" + taskResourceRep.getId().toString()).get(ClientResponse.class);
        Assert.assertEquals(HttpStatus.SC_OK, clientResponse.getStatus());
        taskResourceRep = clientResponse.getEntity(TaskResourceRep.class);
        Assert.assertNotNull(taskResourceRep.getResource().getId());
    }
    return taskResourceRep.getResource().getId();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) TaskResourceRep(com.emc.storageos.model.TaskResourceRep)

Example 47 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class ComputeSystemServiceApiTest method createAndDiscoverComputeSystem.

private TaskResourceRep createAndDiscoverComputeSystem(String ip, String username, String password, String name, int portname) throws Exception {
    TaskResourceRep taskCreateComputeSystem = null;
    ComputeSystemCreate computeSystemCreate = new ComputeSystemCreate();
    computeSystemCreate.setIpAddress(ip);
    computeSystemCreate.setName(name);
    computeSystemCreate.setPassword(password);
    computeSystemCreate.setUserName(username);
    computeSystemCreate.setPortNumber(portname);
    computeSystemCreate.setSystemType(ComputeSystem.Type.ucs.name());
    return taskCreateComputeSystem = rSys.path(COMPUTE_SYSTEM_RESOURCE).post(TaskResourceRep.class, computeSystemCreate);
}
Also used : TaskResourceRep(com.emc.storageos.model.TaskResourceRep) ComputeSystemCreate(com.emc.storageos.model.compute.ComputeSystemCreate)

Example 48 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class ApiTest method checkFSCreate.

private void checkFSCreate(BalancedWebResource user, boolean good, boolean dup) throws Exception {
    FileSystemParam fsparam = new FileSystemParam();
    fsparam.setVpool(_cosFile.getId());
    fsparam.setLabel("test-fs-" + System.currentTimeMillis());
    fsparam.setVarray(_nh);
    fsparam.setSize("20480000");
    if (good) {
        TaskResourceRep resp = user.path("/file/filesystems/").queryParam("project", _testProject.toString()).post(TaskResourceRep.class, fsparam);
        Assert.assertNotNull(resp.getOpId());
        Assert.assertNotNull(resp.getResource());
        _fs = resp.getResource().getId();
        String fsId = _fs.toString();
        String opId = resp.getOpId();
        int checkCount = 1200;
        String status;
        do {
            // wait upto ~2 minute for fs creation
            Thread.sleep(100);
            resp = user.path(String.format("/file/filesystems/%s/tasks/%s", fsId, opId)).get(TaskResourceRep.class);
            status = resp.getState();
        } while (status.equals("pending") && checkCount-- > 0);
        if (!status.equals("ready")) {
            Assert.assertTrue("Fileshare create timed out", false);
        }
        if (dup) {
            ClientResponse response = user.path("/file/filesystems").queryParam("project", _testProject.toString()).post(ClientResponse.class, fsparam);
            Assert.assertEquals(400, response.getStatus());
        }
    } else {
        ClientResponse resp = user.path("/file/filesystems").queryParam("project", _testProject.toString()).post(ClientResponse.class, fsparam);
        Assert.assertEquals(403, resp.getStatus());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSystemParam(com.emc.storageos.model.file.FileSystemParam) TaskResourceRep(com.emc.storageos.model.TaskResourceRep)

Example 49 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class ApiTest method checkSnapCreate.

private void checkSnapCreate(BalancedWebResource user, boolean good) {
    FileSystemSnapshotParam param = new FileSystemSnapshotParam();
    param.setLabel("test-fs-snap-" + System.currentTimeMillis());
    String snapCreateURL = String.format("/file/filesystems/%s/snapshots", _fs);
    if (good) {
        TaskResourceRep resp = user.path(snapCreateURL).post(TaskResourceRep.class, param);
        Assert.assertNotNull(resp.getOpId());
        Assert.assertNotNull(resp.getResource());
    } else {
        ClientResponse resp = user.path(snapCreateURL).post(ClientResponse.class, param);
        Assert.assertEquals(403, resp.getStatus());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSystemSnapshotParam(com.emc.storageos.model.file.FileSystemSnapshotParam) TaskResourceRep(com.emc.storageos.model.TaskResourceRep)

Example 50 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class ApiTest method testVDCs.

// TODO: to be moved in another test suite
public void testVDCs() {
    // TODO: once devkit gets switched to 1+0 appliance, we should enable it again.
    if (System.getenv("APP_HOST_NAMES").equals("localhost")) {
        return;
    }
    VirtualDataCenterAddParam addParam = new VirtualDataCenterAddParam();
    addParam.setApiEndpoint("http://apitest");
    addParam.setSecretKey("apitestSecret");
    addParam.setCertificateChain("apitestCertchain");
    addParam.setName("apitestName" + System.currentTimeMillis());
    // TODO: enhance to track task progress
    // root should NOT do this.
    ClientResponse rsp = rSys.path("/vdc").post(ClientResponse.class, addParam);
    Assert.assertEquals(403, rsp.getStatus());
    // use super admin with geo securityAdmin role to do post vdc
    // assign geo securityadmin to superuser.
    RoleAssignmentChanges changes = new RoleAssignmentChanges();
    changes.setAdd(new ArrayList<RoleAssignmentEntry>());
    RoleAssignmentEntry entry1 = new RoleAssignmentEntry();
    entry1.setSubjectId(SUPERUSER);
    entry1.getRoles().add("SECURITY_ADMIN");
    changes.getAdd().add(entry1);
    ClientResponse rsp1 = rSys.path("/vdc/role-assignments").put(ClientResponse.class, changes);
    Assert.assertEquals(200, rsp1.getStatus());
    // then do post VDC using superuser. should pass.
    TaskResourceRep taskRep = rZAdminGr.path("/vdc").post(TaskResourceRep.class, addParam);
    Assert.assertNotNull("vdc create task should not be null", taskRep);
    VirtualDataCenterList vdcList = rSys.path("/vdc").get(VirtualDataCenterList.class);
    Assert.assertNotNull("vdcList should not be null", vdcList);
    Assert.assertNotNull("vdcList.getVirtualDataCenters should not be null", vdcList.getVirtualDataCenters());
    // boolean found = false;
    // for (NamedRelatedResourceRep vdcResource : vdcList.getVirtualDataCenters()) {
    // if (vdcResource.getName().equals(addParam.getName())) {
    // found = true;
    // }
    // }
    // Assert.assertTrue("newly created vdc could not be found in vdc list", found);
    VirtualDataCenterRestRep vdc = rZAdminGr.path("/vdc/" + taskRep.getResource().getId()).get(VirtualDataCenterRestRep.class);
    Assert.assertNotNull("created vdc object can't be retrieved", vdc);
    Assert.assertTrue("vdc name does not match", vdc.getName().equals(addParam.getName()));
    // TODO: enhance to track task progress
    ClientResponse response = rZAdminGr.path("/vdc/" + vdc.getId() + "/disconnect").post(ClientResponse.class);
    Assert.assertEquals(405, response.getStatus());
    // TODO: enhance to track task progress
    response = rZAdminGr.path("/vdc/" + vdc.getId() + "/reconnect").post(ClientResponse.class);
    Assert.assertEquals(405, response.getStatus());
    // TODO: enhance to track task progress
    taskRep = rZAdminGr.path("/vdc/" + vdc.getId()).delete(TaskResourceRep.class);
    Assert.assertNotNull("vdc delete task should not be null", taskRep);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RoleAssignmentChanges(com.emc.storageos.model.auth.RoleAssignmentChanges) VirtualDataCenterList(com.emc.storageos.model.vdc.VirtualDataCenterList) VirtualDataCenterRestRep(com.emc.storageos.model.vdc.VirtualDataCenterRestRep) RoleAssignmentEntry(com.emc.storageos.model.auth.RoleAssignmentEntry) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualDataCenterAddParam(com.emc.storageos.model.vdc.VirtualDataCenterAddParam)

Aggregations

TaskResourceRep (com.emc.storageos.model.TaskResourceRep)160 URI (java.net.URI)85 TaskList (com.emc.storageos.model.TaskList)82 Operation (com.emc.storageos.db.client.model.Operation)68 Produces (javax.ws.rs.Produces)59 ArrayList (java.util.ArrayList)56 Volume (com.emc.storageos.db.client.model.Volume)55 Path (javax.ws.rs.Path)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)53 POST (javax.ws.rs.POST)50 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)49 Consumes (javax.ws.rs.Consumes)36 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)35 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 NamedURI (com.emc.storageos.db.client.model.NamedURI)30 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)23 Project (com.emc.storageos.db.client.model.Project)20 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)18 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)17 Copy (com.emc.storageos.model.block.Copy)17