Search in sources :

Example 1 with VirtualDataCenterAddParam

use of com.emc.storageos.model.vdc.VirtualDataCenterAddParam 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)

Example 2 with VirtualDataCenterAddParam

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

the class VdcApiProxyUserTest method getVdcAddParam.

private VirtualDataCenterAddParam getVdcAddParam() {
    VirtualDataCenterAddParam newVdcParam;
    newVdcParam = new VirtualDataCenterAddParam();
    newVdcParam.setName("new_vdc_" + new Random().nextInt());
    newVdcParam.setApiEndpoint("fake-endpoint");
    newVdcParam.setDescription("description");
    newVdcParam.setSecretKey("fake-secretkey");
    return newVdcParam;
}
Also used : Random(java.util.Random) VirtualDataCenterAddParam(com.emc.storageos.model.vdc.VirtualDataCenterAddParam)

Example 3 with VirtualDataCenterAddParam

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

the class VirtualDataCenters method save.

@FlashException(keep = true, referrer = { "create", "edit" })
@Restrictions({ @Restrict("SYSTEM_ADMIN"), @Restrict("SECURITY_ADMIN"), @Restrict("RESTRICTED_SECURITY_ADMIN") })
public static void save(VirtualDataCenterForm vdc) {
    vdc.validate("vdc");
    if (Validation.hasErrors()) {
        Common.handleError();
    }
    if (vdc.isNew()) {
        VirtualDataCenterAddParam vdcToAdd = new VirtualDataCenterAddParam();
        vdcToAdd.setName(vdc.name);
        vdcToAdd.setApiEndpoint(vdc.apiEndpoint);
        vdcToAdd.setDescription(vdc.description);
        vdcToAdd.setSecretKey(vdc.secretKey);
        try {
            vdcToAdd.setCertificateChain(FileUtils.readFileToString(vdc.certChain));
        } catch (Exception e) {
            flash.error(MessagesUtils.get("vdc.certChain.invalid.error"));
            Common.handleError();
        }
        Task<VirtualDataCenterRestRep> task = VirtualDataCenterUtils.create(vdcToAdd);
        flash.put("inProgressTask", task.getTaskResource().getId());
    } else {
        VirtualDataCenterRestRep currentVDC = VirtualDataCenterUtils.get(vdc.id);
        if (currentVDC != null) {
            VirtualDataCenterModifyParam vdcToUpdate = new VirtualDataCenterModifyParam();
            vdcToUpdate.setName(vdc.name);
            vdcToUpdate.setDescription(vdc.description);
            Task<VirtualDataCenterRestRep> task = VirtualDataCenterUtils.update(uri(vdc.id), vdcToUpdate);
            flash.put("inProgressTask", task.getTaskResource().getId());
        }
    }
    Cache.delete(Common.VDCS);
    if (StringUtils.isNotBlank(vdc.referrerUrl)) {
        redirect(vdc.referrerUrl);
    } else {
        list();
    }
}
Also used : VirtualDataCenterRestRep(com.emc.storageos.model.vdc.VirtualDataCenterRestRep) VirtualDataCenterAddParam(com.emc.storageos.model.vdc.VirtualDataCenterAddParam) FlashException(controllers.util.FlashException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VirtualDataCenterModifyParam(com.emc.storageos.model.vdc.VirtualDataCenterModifyParam) FlashException(controllers.util.FlashException) Restrictions(controllers.deadbolt.Restrictions)

Aggregations

VirtualDataCenterAddParam (com.emc.storageos.model.vdc.VirtualDataCenterAddParam)3 VirtualDataCenterRestRep (com.emc.storageos.model.vdc.VirtualDataCenterRestRep)2 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1 RoleAssignmentChanges (com.emc.storageos.model.auth.RoleAssignmentChanges)1 RoleAssignmentEntry (com.emc.storageos.model.auth.RoleAssignmentEntry)1 VirtualDataCenterList (com.emc.storageos.model.vdc.VirtualDataCenterList)1 VirtualDataCenterModifyParam (com.emc.storageos.model.vdc.VirtualDataCenterModifyParam)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 Restrictions (controllers.deadbolt.Restrictions)1 FlashException (controllers.util.FlashException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Random (java.util.Random)1