Search in sources :

Example 11 with Instance

use of com.ctrip.framework.apollo.biz.entity.Instance in project apollo by ctripcorp.

the class InstanceServiceTest method testCreateAndFindInstance.

@Test
@Rollback
public void testCreateAndFindInstance() throws Exception {
    String someAppId = "someAppId";
    String someClusterName = "someClusterName";
    String someDataCenter = "someDataCenter";
    String someIp = "someIp";
    Instance instance = instanceService.findInstance(someAppId, someClusterName, someDataCenter, someIp);
    assertNull(instance);
    instanceService.createInstance(assembleInstance(someAppId, someClusterName, someDataCenter, someIp));
    instance = instanceService.findInstance(someAppId, someClusterName, someDataCenter, someIp);
    assertNotEquals(0, instance.getId());
}
Also used : Instance(com.ctrip.framework.apollo.biz.entity.Instance) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Rollback(org.springframework.test.annotation.Rollback)

Example 12 with Instance

use of com.ctrip.framework.apollo.biz.entity.Instance in project apollo by ctripcorp.

the class InstanceServiceTest method testFindInstancesByNamespaceAndInstanceAppId.

@Test
@Rollback
public void testFindInstancesByNamespaceAndInstanceAppId() throws Exception {
    String someConfigAppId = "someConfigAppId";
    String someConfigClusterName = "someConfigClusterName";
    String someConfigNamespaceName = "someConfigNamespaceName";
    String someReleaseKey = "someReleaseKey";
    Date someValidDate = new Date();
    String someAppId = "someAppId";
    String anotherAppId = "anotherAppId";
    String someClusterName = "someClusterName";
    String someDataCenter = "someDataCenter";
    String someIp = "someIp";
    Instance someInstance = instanceService.createInstance(assembleInstance(someAppId, someClusterName, someDataCenter, someIp));
    Instance anotherInstance = instanceService.createInstance(assembleInstance(anotherAppId, someClusterName, someDataCenter, someIp));
    prepareInstanceConfigForInstance(someInstance.getId(), someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
    prepareInstanceConfigForInstance(anotherInstance.getId(), someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
    Page<Instance> result = instanceService.findInstancesByNamespaceAndInstanceAppId(someAppId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
    Page<Instance> anotherResult = instanceService.findInstancesByNamespaceAndInstanceAppId(anotherAppId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
    assertEquals(Lists.newArrayList(someInstance), result.getContent());
    assertEquals(Lists.newArrayList(anotherInstance), anotherResult.getContent());
}
Also used : Instance(com.ctrip.framework.apollo.biz.entity.Instance) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Rollback(org.springframework.test.annotation.Rollback)

Example 13 with Instance

use of com.ctrip.framework.apollo.biz.entity.Instance in project apollo by ctripcorp.

the class InstanceServiceTest method testFindInstancesByNamespace.

@Test
@Rollback
public void testFindInstancesByNamespace() throws Exception {
    String someConfigAppId = "someConfigAppId";
    String someConfigClusterName = "someConfigClusterName";
    String someConfigNamespaceName = "someConfigNamespaceName";
    String someReleaseKey = "someReleaseKey";
    Date someValidDate = new Date();
    String someAppId = "someAppId";
    String someClusterName = "someClusterName";
    String someDataCenter = "someDataCenter";
    String someIp = "someIp";
    String anotherIp = "anotherIp";
    Instance someInstance = instanceService.createInstance(assembleInstance(someAppId, someClusterName, someDataCenter, someIp));
    Instance anotherInstance = instanceService.createInstance(assembleInstance(someAppId, someClusterName, someDataCenter, anotherIp));
    prepareInstanceConfigForInstance(someInstance.getId(), someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
    prepareInstanceConfigForInstance(anotherInstance.getId(), someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
    Page<Instance> result = instanceService.findInstancesByNamespace(someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
    assertEquals(Lists.newArrayList(someInstance, anotherInstance), result.getContent());
}
Also used : Instance(com.ctrip.framework.apollo.biz.entity.Instance) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Rollback(org.springframework.test.annotation.Rollback)

Example 14 with Instance

use of com.ctrip.framework.apollo.biz.entity.Instance in project apollo by ctripcorp.

the class InstanceConfigAuditUtil method prepareInstanceId.

private long prepareInstanceId(InstanceConfigAuditModel auditModel) {
    Instance instance = instanceService.findInstance(auditModel.getAppId(), auditModel.getClusterName(), auditModel.getDataCenter(), auditModel.getIp());
    if (instance != null) {
        return instance.getId();
    }
    instance = new Instance();
    instance.setAppId(auditModel.getAppId());
    instance.setClusterName(auditModel.getClusterName());
    instance.setDataCenter(auditModel.getDataCenter());
    instance.setIp(auditModel.getIp());
    try {
        return instanceService.createInstance(instance).getId();
    } catch (DataIntegrityViolationException ex) {
        // return the one exists
        return instanceService.findInstance(instance.getAppId(), instance.getClusterName(), instance.getDataCenter(), instance.getIp()).getId();
    }
}
Also used : Instance(com.ctrip.framework.apollo.biz.entity.Instance) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 15 with Instance

use of com.ctrip.framework.apollo.biz.entity.Instance in project apollo by ctripcorp.

the class InstanceConfigControllerTest method testGetByReleasesNotIn.

@Test
public void testGetByReleasesNotIn() throws Exception {
    String someConfigAppId = "someConfigAppId";
    String someConfigClusterName = "someConfigClusterName";
    String someConfigNamespaceName = "someConfigNamespaceName";
    long someReleaseId = 1;
    long anotherReleaseId = 2;
    String releaseIds = Joiner.on(",").join(someReleaseId, anotherReleaseId);
    Date someReleaseDeliveryTime = new Date();
    Date anotherReleaseDeliveryTime = new Date();
    Release someRelease = mock(Release.class);
    Release anotherRelease = mock(Release.class);
    String someReleaseKey = "someReleaseKey";
    String anotherReleaseKey = "anotherReleaseKey";
    when(someRelease.getReleaseKey()).thenReturn(someReleaseKey);
    when(anotherRelease.getReleaseKey()).thenReturn(anotherReleaseKey);
    when(releaseService.findByReleaseIds(Sets.newHashSet(someReleaseId, anotherReleaseId))).thenReturn(Lists.newArrayList(someRelease, anotherRelease));
    long someInstanceId = 1;
    long anotherInstanceId = 2;
    String someInstanceConfigReleaseKey = "someInstanceConfigReleaseKey";
    String anotherInstanceConfigReleaseKey = "anotherInstanceConfigReleaseKey";
    InstanceConfig someInstanceConfig = mock(InstanceConfig.class);
    InstanceConfig anotherInstanceConfig = mock(InstanceConfig.class);
    when(someInstanceConfig.getInstanceId()).thenReturn(someInstanceId);
    when(anotherInstanceConfig.getInstanceId()).thenReturn(anotherInstanceId);
    when(someInstanceConfig.getReleaseKey()).thenReturn(someInstanceConfigReleaseKey);
    when(anotherInstanceConfig.getReleaseKey()).thenReturn(anotherInstanceConfigReleaseKey);
    when(someInstanceConfig.getReleaseDeliveryTime()).thenReturn(someReleaseDeliveryTime);
    when(anotherInstanceConfig.getReleaseDeliveryTime()).thenReturn(anotherReleaseDeliveryTime);
    when(instanceService.findInstanceConfigsByNamespaceWithReleaseKeysNotIn(someConfigAppId, someConfigClusterName, someConfigNamespaceName, Sets.newHashSet(someReleaseKey, anotherReleaseKey))).thenReturn(Lists.newArrayList(someInstanceConfig, anotherInstanceConfig));
    String someInstanceAppId = "someInstanceAppId";
    String someInstanceClusterName = "someInstanceClusterName";
    String someInstanceNamespaceName = "someInstanceNamespaceName";
    String someIp = "someIp";
    String anotherIp = "anotherIp";
    Instance someInstance = assembleInstance(someInstanceId, someInstanceAppId, someInstanceClusterName, someInstanceNamespaceName, someIp);
    Instance anotherInstance = assembleInstance(anotherInstanceId, someInstanceAppId, someInstanceClusterName, someInstanceNamespaceName, anotherIp);
    when(instanceService.findInstancesByIds(Sets.newHashSet(someInstanceId, anotherInstanceId))).thenReturn(Lists.newArrayList(someInstance, anotherInstance));
    Release someInstanceConfigRelease = new Release();
    someInstanceConfigRelease.setReleaseKey(someInstanceConfigReleaseKey);
    Release anotherInstanceConfigRelease = new Release();
    anotherInstanceConfigRelease.setReleaseKey(anotherInstanceConfigReleaseKey);
    when(releaseService.findByReleaseKeys(Sets.newHashSet(someInstanceConfigReleaseKey, anotherInstanceConfigReleaseKey))).thenReturn(Lists.newArrayList(someInstanceConfigRelease, anotherInstanceConfigRelease));
    List<InstanceDTO> result = instanceConfigController.getByReleasesNotIn(someConfigAppId, someConfigClusterName, someConfigNamespaceName, releaseIds);
    assertEquals(2, result.size());
    InstanceDTO someInstanceDto = null;
    InstanceDTO anotherInstanceDto = null;
    for (InstanceDTO instanceDTO : result) {
        if (instanceDTO.getId() == someInstanceId) {
            someInstanceDto = instanceDTO;
        } else if (instanceDTO.getId() == anotherInstanceId) {
            anotherInstanceDto = instanceDTO;
        }
    }
    verifyInstance(someInstance, someInstanceDto);
    verifyInstance(anotherInstance, anotherInstanceDto);
    assertEquals(someInstanceConfigReleaseKey, someInstanceDto.getConfigs().get(0).getRelease().getReleaseKey());
    assertEquals(anotherInstanceConfigReleaseKey, anotherInstanceDto.getConfigs().get(0).getRelease().getReleaseKey());
    assertEquals(someReleaseDeliveryTime, someInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
    assertEquals(anotherReleaseDeliveryTime, anotherInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
}
Also used : InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Instance(com.ctrip.framework.apollo.biz.entity.Instance) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) Date(java.util.Date) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Aggregations

Instance (com.ctrip.framework.apollo.biz.entity.Instance)15 Test (org.junit.Test)10 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)6 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)6 Date (java.util.Date)6 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)5 Rollback (org.springframework.test.annotation.Rollback)5 Release (com.ctrip.framework.apollo.biz.entity.Release)4 PageImpl (org.springframework.data.domain.PageImpl)3 InstanceService (com.ctrip.framework.apollo.biz.service.InstanceService)2 ReleaseService (com.ctrip.framework.apollo.biz.service.ReleaseService)2 InstanceConfigDTO (com.ctrip.framework.apollo.common.dto.InstanceConfigDTO)2 PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)2 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)2 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)2 BeanUtils (com.ctrip.framework.apollo.common.utils.BeanUtils)2 Splitter (com.google.common.base.Splitter)2 Strings (com.google.common.base.Strings)2 HashMultimap (com.google.common.collect.HashMultimap)2 Maps (com.google.common.collect.Maps)2