Search in sources :

Example 1 with RemoveRecordCommand

use of com.globo.globodns.cloudstack.commands.RemoveRecordCommand in project cloudstack by apache.

the class GloboDnsElement method release.

@Override
@DB
public boolean release(final Network network, NicProfile nic, final VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
    if (!isTypeSupported(vm.getType())) {
        s_logger.info("GloboDNS only manages records for VMs of type User, ConsoleProxy and DomainRouter. VM " + vm + " is " + vm.getType());
        return false;
    }
    Long zoneId = network.getDataCenterId();
    final DataCenter zone = _dcDao.findById(zoneId);
    if (zone == null) {
        throw new CloudRuntimeException("Could not find zone associated to this network");
    }
    RemoveRecordCommand cmd = new RemoveRecordCommand(hostNameOfVirtualMachine(vm), nic.getIPv4Address(), network.getNetworkDomain(), GloboDNSOverride.value());
    callCommand(cmd, zoneId);
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) DB(com.cloud.utils.db.DB)

Example 2 with RemoveRecordCommand

use of com.globo.globodns.cloudstack.commands.RemoveRecordCommand in project cloudstack by apache.

the class GloboDnsResourceTest method testRemoveReverseRecordButNotRemoveRecordWhenRecordExistsWithDifferentValueAndOverrideIsFalse.

@Test
public void testRemoveReverseRecordButNotRemoveRecordWhenRecordExistsWithDifferentValueAndOverrideIsFalse() throws Exception {
    String recordName = "recordname";
    String recordIp = "40.30.20.10";
    String domainName = "domain.name.com";
    String reverseDomainName = "20.30.40.in-addr.arpa";
    String reverseRecordName = "10";
    String reverseRecordContent = recordName + "." + domainName;
    Domain domain = generateFakeDomain(domainName, false);
    Record record = generateFakeRecord(domain, recordName, "X", false);
    Domain reverseDomain = generateFakeDomain(reverseDomainName, true);
    Record reverseRecord = generateFakeRecord(reverseDomain, reverseRecordName, reverseRecordContent, true);
    Answer answer = _globoDnsResource.execute(new RemoveRecordCommand(recordName, recordIp, domainName, false));
    assertEquals(true, answer.getResult());
    verify(_recordApi, never()).removeRecord(eq(record.getId()));
    verify(_recordApi, times(1)).removeRecord(eq(reverseRecord.getId()));
    verify(_exportApi, times(1)).scheduleExport();
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) Domain(com.globo.globodns.client.model.Domain) Test(org.junit.Test)

Example 3 with RemoveRecordCommand

use of com.globo.globodns.cloudstack.commands.RemoveRecordCommand in project cloudstack by apache.

the class GloboDnsResourceTest method testRemoveDomainWithSuccessButDomainKeptWhenDomainExistsAndThereAreRecordsAndOverrideIsFalse.

// ///////////////////////
// Remove Domain tests //
// ///////////////////////
@Test
public void testRemoveDomainWithSuccessButDomainKeptWhenDomainExistsAndThereAreRecordsAndOverrideIsFalse() throws Exception {
    String recordName = "recordname";
    String recordIp = "40.30.20.10";
    String domainName = "domain.name.com";
    Domain domain = generateFakeDomain(domainName, false);
    Record record = generateFakeRecord(domain, recordName, "X", false);
    when(_recordApi.listAll(domain.getId())).thenReturn(Arrays.asList(record));
    Answer answer = _globoDnsResource.execute(new RemoveRecordCommand(recordName, recordIp, domainName, false));
    assertEquals(true, answer.getResult());
    verify(_domainApi, never()).removeDomain(any(Long.class));
    verify(_exportApi, never()).scheduleExport();
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) Domain(com.globo.globodns.client.model.Domain) Test(org.junit.Test)

Example 4 with RemoveRecordCommand

use of com.globo.globodns.cloudstack.commands.RemoveRecordCommand in project cloudstack by apache.

the class GloboDnsResourceTest method testRemoveRecordWithSuccessAndReverseRecordNotRemovedWhenReverseRecordExistsWithDifferentValueAndOverrideIsFalse.

@Test
public void testRemoveRecordWithSuccessAndReverseRecordNotRemovedWhenReverseRecordExistsWithDifferentValueAndOverrideIsFalse() throws Exception {
    String recordName = "recordname";
    String recordIp = "40.30.20.10";
    String domainName = "domain.name.com";
    String reverseDomainName = "20.30.40.in-addr.arpa";
    String reverseRecordName = "10";
    Domain domain = generateFakeDomain(domainName, false);
    Record record = generateFakeRecord(domain, recordName, recordIp, false);
    Domain reverseDomain = generateFakeDomain(reverseDomainName, true);
    Record reverseRecord = generateFakeRecord(reverseDomain, reverseRecordName, "X", true);
    Answer answer = _globoDnsResource.execute(new RemoveRecordCommand(recordName, recordIp, domainName, false));
    assertEquals(true, answer.getResult());
    verify(_recordApi, times(1)).removeRecord(eq(record.getId()));
    verify(_recordApi, never()).removeRecord(eq(reverseRecord.getId()));
    verify(_exportApi, times(1)).scheduleExport();
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) Domain(com.globo.globodns.client.model.Domain) Test(org.junit.Test)

Example 5 with RemoveRecordCommand

use of com.globo.globodns.cloudstack.commands.RemoveRecordCommand in project cloudstack by apache.

the class GloboDnsResourceTest method testRemoveRecordWhenRecordExists.

// ///////////////////////
// Remove Record tests //
// ///////////////////////
@Test
public void testRemoveRecordWhenRecordExists() throws Exception {
    String recordName = "recordname";
    String recordIp = "40.30.20.10";
    String domainName = "domain.name.com";
    String reverseDomainName = "20.30.40.in-addr.arpa";
    String reverseRecordName = "10";
    String reverseRecordContent = recordName + "." + domainName;
    Domain domain = generateFakeDomain(domainName, false);
    Record record = generateFakeRecord(domain, recordName, recordIp, false);
    Domain reverseDomain = generateFakeDomain(reverseDomainName, true);
    Record reverseRecord = generateFakeRecord(reverseDomain, reverseRecordName, reverseRecordContent, true);
    Answer answer = _globoDnsResource.execute(new RemoveRecordCommand(recordName, recordIp, domainName, true));
    assertNotNull(answer);
    assertEquals(true, answer.getResult());
    verify(_recordApi, times(1)).removeRecord(eq(record.getId()));
    verify(_recordApi, times(1)).removeRecord(eq(reverseRecord.getId()));
    verify(_exportApi, times(1)).scheduleExport();
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) Domain(com.globo.globodns.client.model.Domain) Test(org.junit.Test)

Aggregations

RemoveRecordCommand (com.globo.globodns.cloudstack.commands.RemoveRecordCommand)5 Answer (com.cloud.agent.api.Answer)4 Domain (com.globo.globodns.client.model.Domain)4 Record (com.globo.globodns.client.model.Record)4 Test (org.junit.Test)4 DataCenter (com.cloud.dc.DataCenter)1 DB (com.cloud.utils.db.DB)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1